mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Remove invalid_args error code
Throw std::invalid_argument exceptions instead.
This commit is contained in:
@@ -57,8 +57,6 @@ public:
|
||||
* condition.
|
||||
*/
|
||||
condition_eval_fail = 4,
|
||||
/** An error was encountered due to invalid function arguments. */
|
||||
invalid_args = 7,
|
||||
/** A path could not be found. */
|
||||
path_not_found = 9,
|
||||
/** None of LOOT's supported games could be detected. */
|
||||
|
||||
+2
-2
@@ -59,11 +59,11 @@ LOOT_API std::shared_ptr<DatabaseInterface> CreateDatabase(const GameType game,
|
||||
// Check for valid paths.
|
||||
const std::string resolvedGamePath = ResolvePath(gamePath);
|
||||
if (!gamePath.empty() && !fs::is_directory(resolvedGamePath))
|
||||
throw Error(Error::Code::invalid_args, "Given game path \"" + gamePath + "\" does not resolve to a valid directory.");
|
||||
throw std::invalid_argument("Given game path \"" + gamePath + "\" does not resolve to a valid directory.");
|
||||
|
||||
const std::string resolvedGameLocalPath = ResolvePath(gameLocalPath);
|
||||
if (!gameLocalPath.empty() && !fs::is_directory(resolvedGameLocalPath))
|
||||
throw Error(Error::Code::invalid_args, "Given local data path \"" + gameLocalPath + "\" does not resolve to a valid directory.");
|
||||
throw std::invalid_argument("Given game path \"" + gameLocalPath + "\" does not resolve to a valid directory.");
|
||||
|
||||
return std::make_shared<ApiDatabase>(game, resolvedGamePath, resolvedGameLocalPath);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ bool ApiDatabase::UpdateMasterlist(const std::string& masterlistPath,
|
||||
const std::string& remoteURL,
|
||||
const std::string& remoteBranch) {
|
||||
if (!boost::filesystem::is_directory(boost::filesystem::path(masterlistPath).parent_path()))
|
||||
throw Error(Error::Code::invalid_args, "Given masterlist path \"" + std::string(masterlistPath) + "\" does not have a valid parent directory.");
|
||||
throw std::invalid_argument("Given masterlist path \"" + masterlistPath + "\" does not have a valid parent directory.");
|
||||
|
||||
Masterlist masterlist;
|
||||
return masterlist.Update(masterlistPath, remoteURL, remoteBranch);
|
||||
@@ -216,7 +216,7 @@ PluginCleanliness ApiDatabase::GetPluginCleanliness(const std::string& plugin) {
|
||||
// for output. If outputFile already exists, it will only be overwritten if overwrite is true.
|
||||
void ApiDatabase::WriteMinimalList(const std::string& outputFile, const bool overwrite) {
|
||||
if (!boost::filesystem::exists(boost::filesystem::path(outputFile).parent_path()))
|
||||
throw Error(Error::Code::invalid_args, "Output directory does not exist.");
|
||||
throw std::invalid_argument("Output directory does not exist.");
|
||||
|
||||
if (boost::filesystem::exists(outputFile) && !overwrite)
|
||||
throw Error(Error::Code::path_write_fail, "Output file exists but overwrite is not set to true.");
|
||||
|
||||
@@ -57,7 +57,7 @@ Game::Game(const GameType gameType, const std::string& folder) : GameSettings(ga
|
||||
|
||||
void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppData) {
|
||||
if (Type() != GameType::tes4 && Type() != GameType::tes5 && Type() != GameType::fo3 && Type() != GameType::fonv && Type() != GameType::fo4) {
|
||||
throw Error(Error::Code::invalid_args, translate("Invalid game ID supplied.").str());
|
||||
throw std::invalid_argument(translate("Invalid game ID supplied.").str());
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Initialising filesystem-related data for game: " << Name();
|
||||
@@ -118,7 +118,7 @@ void Game::LoadPlugins(const std::vector<std::string>& plugins, bool headersOnly
|
||||
// First get the plugin sizes.
|
||||
for (const auto& plugin : plugins) {
|
||||
if (!Plugin::IsValid(plugin, *this))
|
||||
throw Error(Error::Code::invalid_args, "\"" + plugin + "\" is not a valid plugin");
|
||||
throw std::invalid_argument("\"" + plugin + "\" is not a valid plugin");
|
||||
|
||||
uintmax_t fileSize = Plugin::GetFileSize(plugin, *this);
|
||||
meanFileSize += fileSize;
|
||||
|
||||
@@ -103,7 +103,7 @@ const Plugin& GameCache::GetPlugin(const std::string & pluginName) const {
|
||||
if (it != end(plugins_))
|
||||
return it->second;
|
||||
|
||||
throw Error(Error::Code::invalid_args, "No plugin \"" + pluginName + "\" exists.");
|
||||
throw std::invalid_argument("No plugin \"" + pluginName + "\" exists.");
|
||||
}
|
||||
|
||||
void GameCache::AddPlugin(const Plugin&& plugin) {
|
||||
|
||||
@@ -46,12 +46,12 @@ void LoadOrderHandler::Init(const GameSettings& game, const boost::filesystem::p
|
||||
&& game.Type() != GameType::fo3
|
||||
&& game.Type() != GameType::fonv
|
||||
&& game.Type() != GameType::fo4) {
|
||||
throw Error(Error::Code::invalid_args, translate("Unsupported game ID supplied.").str());
|
||||
throw std::invalid_argument(translate("Unsupported game ID supplied.").str());
|
||||
}
|
||||
|
||||
if (game.GamePath().empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Game path is not initialised.";
|
||||
throw Error(Error::Code::invalid_args, translate("Game path is not initialised.").str());
|
||||
throw std::invalid_argument(translate("Game path is not initialised.").str());
|
||||
}
|
||||
|
||||
const char * gameLocalDataPath = nullptr;
|
||||
|
||||
@@ -144,7 +144,7 @@ std::string RegKeyStringValue(const std::string& keyStr, const std::string& subk
|
||||
else if (keyStr == "HKEY_USERS")
|
||||
hKey = HKEY_USERS;
|
||||
else
|
||||
throw Error(Error::Code::invalid_args, "Invalid registry key given.");
|
||||
throw std::invalid_argument("Invalid registry key given.");
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Getting string for registry key, subkey and value: " << keyStr << " + " << subkey << " + " << value;
|
||||
LONG ret = RegGetValue(hKey,
|
||||
|
||||
@@ -94,7 +94,7 @@ bool Masterlist::Update(const boost::filesystem::path& path, const std::string&
|
||||
string filename = path.filename().string();
|
||||
|
||||
if (repoUrl.empty() || repoBranch.empty())
|
||||
throw Error(Error::Code::invalid_args, "Repository URL and branch must not be empty.");
|
||||
throw std::invalid_argument("Repository URL and branch must not be empty.");
|
||||
|
||||
// Initialise checkout options.
|
||||
BOOST_LOG_TRIVIAL(debug) << "Setting up checkout options.";
|
||||
|
||||
@@ -168,7 +168,7 @@ void ConditionEvaluator::validatePath(const boost::filesystem::path& path) {
|
||||
|
||||
if (component == ".." && temp.filename() == "..") {
|
||||
BOOST_LOG_TRIVIAL(error) << "Invalid file path: " << path;
|
||||
throw Error(Error::Code::invalid_args, boost::locale::translate("Invalid file path:").str() + " " + path.string());
|
||||
throw std::invalid_argument(boost::locale::translate("Invalid file path:").str() + " " + path.string());
|
||||
}
|
||||
|
||||
temp /= component;
|
||||
@@ -178,7 +178,7 @@ void ConditionEvaluator::validateRegex(const std::string& regexString) {
|
||||
try {
|
||||
std::regex(regexString, std::regex::ECMAScript | std::regex::icase);
|
||||
} catch (std::regex_error& e) {
|
||||
throw Error(Error::Code::invalid_args, (boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % regexString % e.what()).str());
|
||||
throw std::invalid_argument((boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % regexString % e.what()).str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ std::pair<boost::filesystem::path, std::regex> ConditionEvaluator::splitRegex(co
|
||||
reg = std::regex(filename, std::regex::ECMAScript | std::regex::icase);
|
||||
} catch (std::regex_error& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Invalid regex string:" << filename;
|
||||
throw Error(Error::Code::invalid_args, (boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % filename % e.what()).str());
|
||||
throw std::invalid_argument((boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % filename % e.what()).str());
|
||||
}
|
||||
|
||||
return std::pair<boost::filesystem::path, std::regex>(parent, reg);
|
||||
|
||||
@@ -47,7 +47,7 @@ Message::Message(const MessageType type, const std::vector<MessageContent>& cont
|
||||
englishStringExists = true;
|
||||
}
|
||||
if (!englishStringExists)
|
||||
throw Error(Error::Code::invalid_args, "bad conversion: multilingual messages must contain an English content string");
|
||||
throw std::invalid_argument("bad conversion: multilingual messages must contain an English content string");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ void MetadataList::AddPlugin(const PluginMetadata& plugin) {
|
||||
regexPlugins_.push_back(plugin);
|
||||
else {
|
||||
if (!plugins_.insert(plugin).second)
|
||||
throw Error(Error::Code::invalid_args, "Cannot add \"" + plugin.Name() + "\" to the metadata list as another entry already exists.");
|
||||
throw std::invalid_argument("Cannot add \"" + plugin.Name() + "\" to the metadata list as another entry already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,11 +85,11 @@ TEST_P(CreateDatabaseTest, shouldSucceedIfPassedValidParametersWithAbsolutePaths
|
||||
}
|
||||
|
||||
TEST_P(CreateDatabaseTest, shouldThrowIfPassedAGamePathThatDoesNotExist) {
|
||||
EXPECT_ANY_THROW(CreateDatabase(GetParam(), missingPath.string(), localPath.string()));
|
||||
EXPECT_THROW(CreateDatabase(GetParam(), missingPath.string(), localPath.string()), std::invalid_argument);
|
||||
}
|
||||
|
||||
TEST_P(CreateDatabaseTest, shouldThrowIfPassedALocalPathThatDoesNotExist) {
|
||||
EXPECT_ANY_THROW(CreateDatabase(GetParam(), dataPath.parent_path().string(), missingPath.string()));
|
||||
EXPECT_THROW(CreateDatabase(GetParam(), dataPath.parent_path().string(), missingPath.string()), std::invalid_argument);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -51,10 +51,10 @@ INSTANTIATE_TEST_CASE_P(,
|
||||
TEST_P(LoadOrderHandlerTest, initShouldThrowIfNoGamePathIsSet) {
|
||||
GameSettings game(GetParam());
|
||||
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game), Error);
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game), Error);
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game, localPath), Error);
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game, localPath), Error);
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game), std::invalid_argument);
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game), std::invalid_argument);
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game, localPath), std::invalid_argument);
|
||||
EXPECT_THROW(loadOrderHandler_.Init(game, localPath), std::invalid_argument);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
@@ -155,7 +155,7 @@ TEST_P(ConditionGrammarTest, evaluatingAFileConditionForAnUnsafePathShouldThrow)
|
||||
std::cend(condition),
|
||||
grammar,
|
||||
skipper_,
|
||||
result_), Error);
|
||||
result_), std::invalid_argument);
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, aFileConditionWithAnInvalidRegexShouldThrow) {
|
||||
@@ -166,7 +166,7 @@ TEST_P(ConditionGrammarTest, aFileConditionWithAnInvalidRegexShouldThrow) {
|
||||
std::cend(condition),
|
||||
grammar,
|
||||
skipper_,
|
||||
result_), Error);
|
||||
result_), std::invalid_argument);
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, aFileConditionWithARegexMatchingAPluginThatExistsShouldEvaluateToTrue) {
|
||||
|
||||
Reference in New Issue
Block a user