From 36991f683b030e6ab5b36d8506239e010f22036b Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 11 Jul 2016 18:11:11 +0100 Subject: [PATCH] Rename error class to Error --- src/api/api.cpp | 46 +++++++++---------- src/api/loot_db.cpp | 2 +- src/backend/app/loot_paths.cpp | 2 +- src/backend/app/loot_state.cpp | 6 +-- src/backend/error.h | 6 +-- src/backend/game/game.cpp | 6 +-- src/backend/game/game_cache.cpp | 2 +- src/backend/game/load_order_handler.cpp | 14 +++--- src/backend/helpers/git_helper.cpp | 28 +++++------ src/backend/helpers/helpers.cpp | 8 ++-- src/backend/masterlist.cpp | 8 ++-- src/backend/metadata/condition_grammar.h | 14 +++--- src/backend/metadata/conditional_metadata.cpp | 8 ++-- src/backend/metadata/message.cpp | 2 +- src/backend/metadata/plugin_metadata.cpp | 2 +- src/backend/metadata_list.cpp | 6 +-- src/backend/plugin/plugin_sorter.cpp | 8 ++-- src/gui/query_handler.cpp | 42 ++++++++--------- src/tests/backend/game/game_test.h | 20 ++++---- .../backend/game/load_order_handler_test.h | 24 +++++----- src/tests/backend/helpers/git_helper_test.h | 8 ++-- src/tests/backend/helpers/helpers_test.h | 2 +- .../backend/metadata/condition_grammar_test.h | 12 ++--- .../metadata/conditional_metadata_test.h | 4 +- 24 files changed, 140 insertions(+), 140 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 54462bb3..06286cb7 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -41,20 +41,20 @@ #include #include -const unsigned int loot_ok = loot::error::ok; -const unsigned int loot_error_liblo_error = loot::error::liblo_error; -const unsigned int loot_error_file_write_fail = loot::error::path_write_fail; -const unsigned int loot_error_parse_fail = loot::error::path_read_fail; -const unsigned int loot_error_condition_eval_fail = loot::error::condition_eval_fail; -const unsigned int loot_error_regex_eval_fail = loot::error::regex_eval_fail; -const unsigned int loot_error_no_mem = loot::error::no_mem; -const unsigned int loot_error_invalid_args = loot::error::invalid_args; -const unsigned int loot_error_no_tag_map = loot::error::no_tag_map; -const unsigned int loot_error_path_not_found = loot::error::path_not_found; -const unsigned int loot_error_no_game_detected = loot::error::no_game_detected; -const unsigned int loot_error_git_error = loot::error::git_error; -const unsigned int loot_error_windows_error = loot::error::windows_error; -const unsigned int loot_error_sorting_error = loot::error::sorting_error; +const unsigned int loot_ok = loot::Error::ok; +const unsigned int loot_error_liblo_error = loot::Error::liblo_error; +const unsigned int loot_error_file_write_fail = loot::Error::path_write_fail; +const unsigned int loot_error_parse_fail = loot::Error::path_read_fail; +const unsigned int loot_error_condition_eval_fail = loot::Error::condition_eval_fail; +const unsigned int loot_error_regex_eval_fail = loot::Error::regex_eval_fail; +const unsigned int loot_error_no_mem = loot::Error::no_mem; +const unsigned int loot_error_invalid_args = loot::Error::invalid_args; +const unsigned int loot_error_no_tag_map = loot::Error::no_tag_map; +const unsigned int loot_error_path_not_found = loot::Error::path_not_found; +const unsigned int loot_error_no_game_detected = loot::Error::no_game_detected; +const unsigned int loot_error_git_error = loot::Error::git_error; +const unsigned int loot_error_windows_error = loot::Error::windows_error; +const unsigned int loot_error_sorting_error = loot::Error::sorting_error; const unsigned int loot_return_max = loot_error_sorting_error; // The following are the games identifiers used by the API. @@ -89,13 +89,13 @@ const unsigned int loot_needs_cleaning_unknown = 2; std::string extMessageStr; -unsigned int c_error(const loot::error& e) { +unsigned int c_error(const loot::Error& e) { extMessageStr = e.what(); return e.code(); } unsigned int c_error(const unsigned int code, const std::string& what) { - return c_error(loot::error(code, what.c_str())); + return c_error(loot::Error(code, what.c_str())); } ////////////////////////////// @@ -200,7 +200,7 @@ LOOT_API unsigned int loot_create_db(loot_db ** const db, *db = new loot_db(clientGame, game_path, game_local_path); } - catch (loot::error& e) { + catch (loot::Error& e) { return c_error(e); } catch (std::bad_alloc& e) { @@ -303,7 +303,7 @@ LOOT_API unsigned int loot_eval_lists(loot_db * const db, const unsigned int lan temp.EvalAllConditions(*db, language); userTemp.EvalAllConditions(*db, language); } - catch (loot::error& e) { + catch (loot::Error& e) { return c_error(e); } db->GetMasterlist() = temp; @@ -335,7 +335,7 @@ LOOT_API unsigned int loot_sort_plugins(loot_db * const db, db->setPluginNames(sorter.Sort(*db, loot::Language::english)); } - catch (loot::error &e) { + catch (loot::Error &e) { return c_error(e); } catch (std::bad_alloc& e) { @@ -360,7 +360,7 @@ LOOT_API unsigned int loot_apply_load_order(loot_db * const db, try { db->SetLoadOrder(loadOrder, numPlugins); } - catch (loot::error &e) { + catch (loot::Error &e) { return c_error(e); } @@ -383,7 +383,7 @@ LOOT_API unsigned int loot_update_masterlist(loot_db * const db, loot::Masterlist masterlist; *updated = masterlist.Update(masterlistPath, remoteURL, remoteBranch); } - catch (loot::error &e) { + catch (loot::Error &e) { return c_error(e); } @@ -418,7 +418,7 @@ LOOT_API unsigned int loot_get_masterlist_revision(loot_db * const db, db->setRevisionIdString(id); db->setRevisionDateString(date); } - catch (loot::error &e) { + catch (loot::Error &e) { if (e.code() == loot_ok) return loot_ok; else @@ -532,7 +532,7 @@ LOOT_API unsigned int loot_get_plugin_tags(loot_db * const db, const char * cons db->setAddedTags(tagsAdded); db->setRemovedTags(tagsRemoved); } - catch (loot::error& e) { + catch (loot::Error& e) { return c_error(e); } diff --git a/src/api/loot_db.cpp b/src/api/loot_db.cpp index 10500e54..360c0708 100644 --- a/src/api/loot_db.cpp +++ b/src/api/loot_db.cpp @@ -53,7 +53,7 @@ unsigned int loot_db::getBashTagUid(const std::string& name) const { if (it != end(bashTagMap)) return it->second; - throw loot::error(loot::error::no_tag_map, "The Bash Tag \"" + name + "\" does not exist in the Bash Tag map."); + throw loot::Error(loot::Error::no_tag_map, "The Bash Tag \"" + name + "\" does not exist in the Bash Tag map."); } const std::vector& loot_db::getAddedTagIds() const { diff --git a/src/backend/app/loot_paths.cpp b/src/backend/app/loot_paths.cpp index 8c1ba8fa..b9cf97d7 100644 --- a/src/backend/app/loot_paths.cpp +++ b/src/backend/app/loot_paths.cpp @@ -89,7 +89,7 @@ namespace loot { PWSTR path; if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path) != S_OK) - throw error(error::windows_error, boost::locale::translate("Failed to get %LOCALAPPDATA% path.")); + throw Error(Error::windows_error, boost::locale::translate("Failed to get %LOCALAPPDATA% path.")); boost::filesystem::path localAppDataPath(FromWinWide(path)); CoTaskMemFree(path); diff --git a/src/backend/app/loot_state.cpp b/src/backend/app/loot_state.cpp index 7aa20298..1efc9e4c 100644 --- a/src/backend/app/loot_state.cpp +++ b/src/backend/app/loot_state.cpp @@ -186,8 +186,8 @@ namespace loot { // Update game path in settings object. storeGameSettings(ToGameSettings(_games)); } - catch (loot::error &e) { - if (e.code() == loot::error::no_game_detected) { + catch (loot::Error &e) { + if (e.code() == loot::Error::no_game_detected) { _initErrors.push_back(e.what()); } else { @@ -270,7 +270,7 @@ namespace loot { // If no game can be selected, throw an exception. if (_currentGame == end(_games)) { BOOST_LOG_TRIVIAL(error) << "None of the supported games were detected."; - throw error(error::no_game_detected, translate("None of the supported games were detected.")); + throw Error(Error::no_game_detected, translate("None of the supported games were detected.")); } } diff --git a/src/backend/error.h b/src/backend/error.h index 3ce1dc2f..70919da6 100644 --- a/src/backend/error.h +++ b/src/backend/error.h @@ -29,10 +29,10 @@ #include namespace loot { - class error : public std::exception { + class Error : public std::exception { public: - error(const unsigned int code_arg, const std::string& what_arg) : _code(code_arg), _what(what_arg) {} - ~error() throw() {}; + Error(const unsigned int code_arg, const std::string& what_arg) : _code(code_arg), _what(what_arg) {} + ~Error() throw() {}; unsigned int code() const { return _code; } const char * what() const throw() { return _what.c_str(); } diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp index 92e39857..c4c8299c 100644 --- a/src/backend/game/game.cpp +++ b/src/backend/game/game.cpp @@ -55,14 +55,14 @@ namespace loot { void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppData) { if (Id() != Game::tes4 && Id() != Game::tes5 && Id() != Game::fo3 && Id() != Game::fonv && Id() != Game::fo4) { - throw error(error::invalid_args, lc::translate("Invalid game ID supplied.").str()); + throw Error(Error::invalid_args, lc::translate("Invalid game ID supplied.").str()); } BOOST_LOG_TRIVIAL(info) << "Initialising filesystem-related data for game: " << Name(); if (!this->IsInstalled()) { BOOST_LOG_TRIVIAL(error) << "Game path could not be detected."; - throw error(error::path_not_found, lc::translate("Game path could not be detected.").str()); + throw Error(Error::path_not_found, lc::translate("Game path could not be detected.").str()); } if (createFolder) { @@ -73,7 +73,7 @@ namespace loot { } catch (fs::filesystem_error& e) { BOOST_LOG_TRIVIAL(error) << "Could not create LOOT folder for game. Details: " << e.what(); - throw error(error::path_write_fail, lc::translate("Could not create LOOT folder for game. Details:").str() + " " + e.what()); + throw Error(Error::path_write_fail, lc::translate("Could not create LOOT folder for game. Details:").str() + " " + e.what()); } } diff --git a/src/backend/game/game_cache.cpp b/src/backend/game/game_cache.cpp index 813726bb..b8da1427 100644 --- a/src/backend/game/game_cache.cpp +++ b/src/backend/game/game_cache.cpp @@ -101,7 +101,7 @@ namespace loot { if (it != end(plugins)) return it->second; - throw error(error::invalid_args, "No plugin \"" + pluginName + "\" exists."); + throw Error(Error::invalid_args, "No plugin \"" + pluginName + "\" exists."); } void GameCache::AddPlugin(const Plugin&& plugin) { diff --git a/src/backend/game/load_order_handler.cpp b/src/backend/game/load_order_handler.cpp index 96d93f81..13d73bba 100644 --- a/src/backend/game/load_order_handler.cpp +++ b/src/backend/game/load_order_handler.cpp @@ -47,12 +47,12 @@ namespace loot { && game.Id() != GameSettings::fo3 && game.Id() != GameSettings::fonv && game.Id() != GameSettings::fo4) { - throw error(error::invalid_args, lc::translate("Unsupported game ID supplied.").str()); + throw Error(Error::invalid_args, lc::translate("Unsupported game ID supplied.").str()); } if (game.GamePath().empty()) { BOOST_LOG_TRIVIAL(error) << "Game path is not initialised."; - throw error(error::invalid_args, lc::translate("Game path is not initialised.").str()); + throw Error(Error::invalid_args, lc::translate("Game path is not initialised.").str()); } const char * gameLocalDataPath = nullptr; @@ -93,7 +93,7 @@ namespace loot { err = lc::translate("libloadorder failed to create a game handle. Details:").str() + " " + e; } lo_cleanup(); - throw error(error::liblo_error, err); + throw Error(Error::liblo_error, err); } } @@ -115,7 +115,7 @@ namespace loot { err = lc::translate("libloadorder failed to check if a plugin is active. Details:").str() + " " + e; } lo_cleanup(); - throw error(error::liblo_error, err); + throw Error(Error::liblo_error, err); } return result; @@ -141,7 +141,7 @@ namespace loot { err = lc::translate("libloadorder failed to get the load order. Details:").str() + " " + e; } lo_cleanup(); - throw error(error::liblo_error, err); + throw Error(Error::liblo_error, err); } std::list loadOrder; @@ -168,7 +168,7 @@ namespace loot { err = lc::translate("libloadorder failed to set the load order. Details:").str() + " " + e; } lo_cleanup(); - throw error(error::liblo_error, err); + throw Error(Error::liblo_error, err); } } @@ -187,7 +187,7 @@ namespace loot { try { SetLoadOrder(pluginArr, pluginArrSize); } - catch (error &/*e*/) { + catch (Error &/*e*/) { for (size_t i = 0; i < pluginArrSize; i++) delete[] pluginArr[i]; delete[] pluginArr; diff --git a/src/backend/helpers/git_helper.cpp b/src/backend/helpers/git_helper.cpp index d527d854..5e6ae358 100644 --- a/src/backend/helpers/git_helper.cpp +++ b/src/backend/helpers/git_helper.cpp @@ -88,7 +88,7 @@ namespace loot { errorMessage = (boost::format(lc::translate("Git operation failed. Error: %1%")) % gitError).str(); BOOST_LOG_TRIVIAL(error) << "Git operation failed. Error: " << gitError; - throw loot::error(loot::error::git_error, errorMessage); + throw loot::Error(loot::Error::git_error, errorMessage); } void GitHelper::SetErrorMessage(const std::string& message) { @@ -158,7 +158,7 @@ namespace loot { // Clones a repository and opens it. void GitHelper::Clone(const boost::filesystem::path& path, const std::string& url) { if (this->repo != nullptr) - throw error(error::git_error, "Cannot clone repository that has already been opened."); + throw Error(Error::git_error, "Cannot clone repository that has already been opened."); this->SetErrorMessage(lc::translate("An error occurred while trying to clone the remote masterlist repository.")); // Clone the remote repository. @@ -209,7 +209,7 @@ namespace loot { void GitHelper::Fetch(const std::string& remote) { if (this->repo == nullptr) - throw error(error::git_error, "Cannot fetch updates for repository that has not been opened."); + throw Error(Error::git_error, "Cannot fetch updates for repository that has not been opened."); BOOST_LOG_TRIVIAL(trace) << "Fetching updates from remote."; this->SetErrorMessage(lc::translate("An error occurred while trying to update the masterlist. This could be due to a server-side error. Try again in a few minutes.")); @@ -231,13 +231,13 @@ namespace loot { void GitHelper::CheckoutNewBranch(const std::string& remote, const std::string& branch) { if (this->repo == nullptr) - throw error(error::git_error, "Cannot fetch updates for repository that has not been opened."); + throw Error(Error::git_error, "Cannot fetch updates for repository that has not been opened."); else if (this->commit != nullptr) - throw error(error::git_error, "Cannot fetch repository updates, commit memory already allocated."); + throw Error(Error::git_error, "Cannot fetch repository updates, commit memory already allocated."); else if (this->obj != nullptr) - throw error(error::git_error, "Cannot fetch repository updates, object memory already allocated."); + throw Error(Error::git_error, "Cannot fetch repository updates, object memory already allocated."); else if (this->ref != nullptr) - throw error(error::git_error, "Cannot fetch repository updates, reference memory already allocated."); + throw Error(Error::git_error, "Cannot fetch repository updates, reference memory already allocated."); BOOST_LOG_TRIVIAL(trace) << "Looking up commit referred to by the remote branch \"" << branch << "\"."; this->Call(git_revparse_single(&this->obj, this->repo, (remote + "/" + branch).c_str())); @@ -272,9 +272,9 @@ namespace loot { void GitHelper::CheckoutRevision(const std::string& revision) { if (this->repo == nullptr) - throw error(error::git_error, "Cannot checkout revision for repository that has not been opened."); + throw Error(Error::git_error, "Cannot checkout revision for repository that has not been opened."); else if (this->obj != nullptr) - throw error(error::git_error, "Cannot fetch repository updates, object memory already allocated."); + throw Error(Error::git_error, "Cannot fetch repository updates, object memory already allocated."); // Get an object ID for 'HEAD^'. this->Call(git_revparse_single(&this->obj, this->repo, revision.c_str())); @@ -293,13 +293,13 @@ namespace loot { std::string GitHelper::GetHeadShortId() { if (this->repo == nullptr) - throw error(error::git_error, "Cannot checkout revision for repository that has not been opened."); + throw Error(Error::git_error, "Cannot checkout revision for repository that has not been opened."); else if (this->obj != nullptr) - throw error(error::git_error, "Cannot fetch repository updates, object memory already allocated."); + throw Error(Error::git_error, "Cannot fetch repository updates, object memory already allocated."); else if (this->ref != nullptr) - throw error(error::git_error, "Cannot fetch repository updates, reference memory already allocated."); + throw Error(Error::git_error, "Cannot fetch repository updates, reference memory already allocated."); else if (this->buf.ptr != nullptr) - throw error(error::git_error, "Cannot fetch repository updates, buffer memory already allocated."); + throw Error(Error::git_error, "Cannot fetch repository updates, buffer memory already allocated."); BOOST_LOG_TRIVIAL(trace) << "Getting the Git object for HEAD."; this->Call(git_repository_head(&this->ref, this->repo)); @@ -322,7 +322,7 @@ namespace loot { bool GitHelper::IsFileDifferent(const boost::filesystem::path& repoRoot, const std::string& filename) { if (!IsRepository(repoRoot)) { BOOST_LOG_TRIVIAL(info) << "Unknown masterlist revision: Git repository missing."; - throw error(error::ok, lc::translate("Unknown: Git repository missing")); + throw Error(Error::ok, lc::translate("Unknown: Git repository missing")); } BOOST_LOG_TRIVIAL(debug) << "Existing repository found, attempting to open it."; diff --git a/src/backend/helpers/helpers.cpp b/src/backend/helpers/helpers.cpp index 0f7732e4..bc2952b6 100644 --- a/src/backend/helpers/helpers.cpp +++ b/src/backend/helpers/helpers.cpp @@ -86,7 +86,7 @@ namespace loot { } catch (exception&) { BOOST_LOG_TRIVIAL(error) << "Unable to open \"" << filename.string() << "\" for CRC calculation."; - throw error(error::path_read_fail, (boost::format(lc::translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str()); + throw Error(Error::path_read_fail, (boost::format(lc::translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str()); } BOOST_LOG_TRIVIAL(debug) << "CRC32(\"" << filename.string() << "\"): " << std::hex << chksum << std::dec; return chksum; @@ -124,10 +124,10 @@ namespace loot { #ifdef _WIN32 HINSTANCE ret = ShellExecute(0, NULL, ToWinWide(file.string()).c_str(), NULL, NULL, SW_SHOWNORMAL); if ((int)ret <= 32) - throw error(error::windows_error, lc::translate("Failed to open file in its default application.")); + throw Error(Error::windows_error, lc::translate("Failed to open file in its default application.")); #else if (system(("/usr/bin/xdg-open" + file.string()).c_str()) != 0) - throw error(error::windows_error, lc::translate("Failed to open file in its default application.")); + throw Error(Error::windows_error, lc::translate("Failed to open file in its default application.")); #endif } @@ -149,7 +149,7 @@ namespace loot { else if (keyStr == "HKEY_USERS") hKey = HKEY_USERS; else - throw error(error::invalid_args, "Invalid registry key given."); + throw Error(Error::invalid_args, "Invalid registry key given."); BOOST_LOG_TRIVIAL(trace) << "Getting string for registry key, subkey and value: " << keyStr << " + " << subkey << " + " << value; LONG ret = RegGetValue(hKey, diff --git a/src/backend/masterlist.cpp b/src/backend/masterlist.cpp index e1303b58..c09f722f 100644 --- a/src/backend/masterlist.cpp +++ b/src/backend/masterlist.cpp @@ -43,11 +43,11 @@ namespace loot { if (!fs::exists(path)) { BOOST_LOG_TRIVIAL(info) << "Unknown masterlist revision: No masterlist present."; - throw error(error::ok, lc::translate("N/A: No masterlist present")); + throw Error(Error::ok, lc::translate("N/A: No masterlist present")); } else if (!git.IsRepository(path.parent_path())) { BOOST_LOG_TRIVIAL(info) << "Unknown masterlist revision: Git repository missing."; - throw error(error::ok, lc::translate("Unknown: Git repository missing")); + throw Error(Error::ok, lc::translate("Unknown: Git repository missing")); } BOOST_LOG_TRIVIAL(debug) << "Existing repository found, attempting to open it."; @@ -95,7 +95,7 @@ namespace loot { string filename = path.filename().string(); if (repoUrl.empty() || repoBranch.empty()) - throw error(error::invalid_args, "Repository URL and branch must not be empty."); + throw Error(Error::invalid_args, "Repository URL and branch must not be empty."); // Initialise checkout options. BOOST_LOG_TRIVIAL(debug) << "Setting up checkout options."; @@ -268,7 +268,7 @@ namespace loot { } while (parsingFailed); if (!parsingError.empty()) - throw error(error::ok, parsingError); //Throw an OK because the process still completed in a successful state. + throw Error(Error::ok, parsingError); //Throw an OK because the process still completed in a successful state. return true; } diff --git a/src/backend/metadata/condition_grammar.h b/src/backend/metadata/condition_grammar.h index 46ee0d8c..7c54e7c7 100644 --- a/src/backend/metadata/condition_grammar.h +++ b/src/backend/metadata/condition_grammar.h @@ -152,7 +152,7 @@ namespace loot { if (!IsSafePath(file)) { BOOST_LOG_TRIVIAL(error) << "Invalid file path: " << file; - throw loot::error(loot::error::invalid_args, boost::locale::translate("Invalid file path:").str() + " " + file); + throw loot::Error(loot::Error::invalid_args, boost::locale::translate("Invalid file path:").str() + " " + file); } if (_game == nullptr) @@ -195,7 +195,7 @@ namespace loot { std::regex(regex, std::regex::ECMAScript | std::regex::icase); } catch (std::regex_error& e) { - throw loot::error(loot::error::invalid_args, (boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % regex % e.what()).str()); + throw loot::Error(loot::Error::invalid_args, (boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % regex % e.what()).str()); } std::regex sepReg("/|(\\\\\\\\)", std::regex::ECMAScript); @@ -213,7 +213,7 @@ namespace loot { if (!IsSafePath(parent)) { BOOST_LOG_TRIVIAL(error) << "Invalid folder path: " << parent; - throw loot::error(loot::error::invalid_args, boost::locale::translate("Invalid folder path:").str() + " " + parent.string()); + throw loot::Error(loot::Error::invalid_args, boost::locale::translate("Invalid folder path:").str() + " " + parent.string()); } std::regex reg; @@ -222,7 +222,7 @@ namespace loot { } catch (std::regex_error& e) { BOOST_LOG_TRIVIAL(error) << "Invalid regex string:" << filename; - throw loot::error(loot::error::invalid_args, (boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % filename % e.what()).str()); + throw loot::Error(loot::Error::invalid_args, (boost::format(boost::locale::translate("Invalid regex string \"%1%\": %2%")) % filename % e.what()).str()); } return std::pair(parent, reg); @@ -290,7 +290,7 @@ namespace loot { if (!IsSafePath(file)) { BOOST_LOG_TRIVIAL(error) << "Invalid file path: " << file; - throw loot::error(loot::error::invalid_args, boost::locale::translate("Invalid file path:").str() + " " + file); + throw loot::Error(loot::Error::invalid_args, boost::locale::translate("Invalid file path:").str() + " " + file); } if (_game == nullptr) @@ -378,7 +378,7 @@ namespace loot { void CheckActive(bool& result, const std::string& file) const { if (!IsSafePath(file)) { BOOST_LOG_TRIVIAL(error) << "Invalid file path: " << file; - throw loot::error(loot::error::invalid_args, boost::locale::translate("Invalid file path:").str() + " " + file); + throw loot::Error(loot::Error::invalid_args, boost::locale::translate("Invalid file path:").str() + " " + file); } if (_game == nullptr) @@ -398,7 +398,7 @@ namespace loot { BOOST_LOG_TRIVIAL(error) << "Expected \"" << what.tag << "\" at \"" << context << "\"."; - throw loot::error(loot::error::condition_eval_fail, (boost::format(boost::locale::translate("Expected \"%1%\" at \"%2%\".")) % what.tag % context).str()); + throw loot::Error(loot::Error::condition_eval_fail, (boost::format(boost::locale::translate("Expected \"%1%\" at \"%2%\".")) % what.tag % context).str()); } //Checks that the path (not regex) doesn't go outside any game folders. diff --git a/src/backend/metadata/conditional_metadata.cpp b/src/backend/metadata/conditional_metadata.cpp index fe91240f..235ba17a 100644 --- a/src/backend/metadata/conditional_metadata.cpp +++ b/src/backend/metadata/conditional_metadata.cpp @@ -69,12 +69,12 @@ namespace loot { } catch (std::exception& e) { BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << _condition << "\": " << e.what(); - throw loot::error(loot::error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\": %2%")) % _condition % e.what()).str()); + throw loot::Error(loot::Error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\": %2%")) % _condition % e.what()).str()); } if (!r || begin != end) { BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << _condition << "\"."; - throw loot::error(loot::error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\".")) % _condition).str()); + throw loot::Error(loot::Error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\".")) % _condition).str()); } game.CacheCondition(_condition, eval); @@ -101,12 +101,12 @@ namespace loot { } catch (std::exception& e) { BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << _condition << "\": " << e.what(); - throw loot::error(loot::error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\": %2%")) % _condition % e.what()).str()); + throw loot::Error(loot::Error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\": %2%")) % _condition % e.what()).str()); } if (!r || begin != end) { BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << _condition << "\"."; - throw loot::error(loot::error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\".")) % _condition).str()); + throw loot::Error(loot::Error::condition_eval_fail, (boost::format(lc::translate("Failed to parse condition \"%1%\".")) % _condition).str()); } } } diff --git a/src/backend/metadata/message.cpp b/src/backend/metadata/message.cpp index a5d0eb8e..69654f21 100644 --- a/src/backend/metadata/message.cpp +++ b/src/backend/metadata/message.cpp @@ -51,7 +51,7 @@ namespace loot { englishStringExists = true; } if (!englishStringExists) - throw loot::error(error::invalid_args, "bad conversion: multilingual messages must contain an English content string"); + throw loot::Error(Error::invalid_args, "bad conversion: multilingual messages must contain an English content string"); } } diff --git a/src/backend/metadata/plugin_metadata.cpp b/src/backend/metadata/plugin_metadata.cpp index 7cde12b5..3f6bf8d5 100644 --- a/src/backend/metadata/plugin_metadata.cpp +++ b/src/backend/metadata/plugin_metadata.cpp @@ -277,7 +277,7 @@ namespace loot { void PluginMetadata::Priority(const int p) { if (abs(p) >= yamlGlobalPriorityDivisor) - throw error(error::invalid_args, "Cannot set priority that has an absolute value greater than or equal to " + to_string(yamlGlobalPriorityDivisor)); + throw Error(Error::invalid_args, "Cannot set priority that has an absolute value greater than or equal to " + to_string(yamlGlobalPriorityDivisor)); priority = p; } diff --git a/src/backend/metadata_list.cpp b/src/backend/metadata_list.cpp index c063e62d..bac5ad5d 100644 --- a/src/backend/metadata_list.cpp +++ b/src/backend/metadata_list.cpp @@ -39,7 +39,7 @@ namespace loot { boost::filesystem::ifstream in(filepath); if (!in.good()) - throw error(error::path_read_fail, "Cannot open " + filepath.string()); + throw Error(Error::path_read_fail, "Cannot open " + filepath.string()); YAML::Node metadataList = YAML::Load(in); in.close(); @@ -51,7 +51,7 @@ namespace loot { regexPlugins.push_back(plugin); else { if (!plugins.insert(plugin).second) - throw error(error::path_read_fail, "More than one entry exists for \"" + plugin.Name() + "\""); + throw Error(Error::path_read_fail, "More than one entry exists for \"" + plugin.Name() + "\""); } } } @@ -127,7 +127,7 @@ namespace loot { regexPlugins.push_back(plugin); else { if (!plugins.insert(plugin).second) - throw error(error::invalid_args, "Cannot add \"" + plugin.Name() + "\" to the metadata list as another entry already exists."); + throw Error(Error::invalid_args, "Cannot add \"" + plugin.Name() + "\" to the metadata list as another entry already exists."); } } diff --git a/src/backend/plugin/plugin_sorter.cpp b/src/backend/plugin/plugin_sorter.cpp index f2c3f6ee..a5634b5b 100644 --- a/src/backend/plugin/plugin_sorter.cpp +++ b/src/backend/plugin/plugin_sorter.cpp @@ -76,7 +76,7 @@ namespace loot { BOOST_LOG_TRIVIAL(error) << "Cyclic interaction detected between plugins \"" << graph[source].Name() << "\" and \"" << graph[target].Name() << "\". Back cycle: " << backCycle; - throw loot::error(loot::error::sorting_error, (boost::format(boost::locale::translate("Cyclic interaction detected between plugins \"%1%\" and \"%2%\". Back cycle: %3%")) % graph[source].Name() % graph[target].Name() % backCycle).str()); + throw loot::Error(loot::Error::sorting_error, (boost::format(boost::locale::translate("Cyclic interaction detected between plugins \"%1%\" and \"%2%\". Back cycle: %3%")) % graph[source].Name() % graph[target].Name() % backCycle).str()); } private: @@ -89,7 +89,7 @@ namespace loot { inline void discover_vertex(vertex_t vertex, const PluginGraph& graph) { if (vertex == target) - throw error(error::ok, "Found a path."); + throw Error(Error::ok, "Found a path."); } private: @@ -246,8 +246,8 @@ namespace loot { try { boost::breadth_first_search(graph, toVertex, visitor(PathDetector(fromVertex)).vertex_index_map(vertexIndexMap)); } - catch (error& e) { - if (e.code() == error::ok) + catch (Error& e) { + if (e.code() == Error::ok) return true; } return false; diff --git a/src/gui/query_handler.cpp b/src/gui/query_handler.cpp index 35968daa..801d33d1 100644 --- a/src/gui/query_handler.cpp +++ b/src/gui/query_handler.cpp @@ -71,7 +71,7 @@ namespace loot { OpenReadme(); callback->Success(""); } - catch (error &e) { + catch (Error &e) { BOOST_LOG_TRIVIAL(error) << e.what(); callback->Failure(e.code(), e.what()); } @@ -86,7 +86,7 @@ namespace loot { OpenLogLocation(); callback->Success(""); } - catch (error &e) { + catch (Error &e) { BOOST_LOG_TRIVIAL(error) << e.what(); callback->Failure(e.code(), e.what()); } @@ -135,7 +135,7 @@ namespace loot { _lootState.CurrentGame().RedatePlugins(); callback->Success(""); } - catch (error &e) { + catch (Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to redate plugins. " << e.what(); callback->Failure(e.code(), e.what()); } @@ -222,7 +222,7 @@ namespace loot { CefPostTask(TID_FILE, base::Bind(&QueryHandler::GetGameData, base::Unretained(this), frame, callback)); } - catch (loot::error &e) { + catch (loot::Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to change game. Details: " << e.what(); callback->Failure(e.code(), (boost::format(loc::translate("Failed to change game. Details: %1%")) % e.what()).str()); } @@ -243,7 +243,7 @@ namespace loot { CopyMetadata(request["args"][0].as()); callback->Success(""); } - catch (loot::error &e) { + catch (loot::Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to copy plugin metadata. Details: " << e.what(); callback->Failure(e.code(), (boost::format(loc::translate("Failed to copy plugin metadata. Details: %1%")) % e.what()).str()); } @@ -265,7 +265,7 @@ namespace loot { callback->Success(ApplyUserEdits(request["args"][0])); _lootState.decrementUnappliedChangeCounter(); } - catch (loot::error &e) { + catch (loot::Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to apply plugin metadata. Details: " << e.what(); callback->Failure(e.code(), (boost::format(loc::translate("Failed to apply plugin metadata. Details: %1%")) % e.what()).str()); } @@ -309,7 +309,7 @@ namespace loot { _lootState.CurrentGame().SetLoadOrder(request["args"][0].as>()); callback->Success(""); } - catch (error &e) { + catch (Error &e) { BOOST_LOG_TRIVIAL(error) << e.what(); callback->Failure(e.code(), e.what()); } @@ -333,7 +333,7 @@ namespace loot { CopyToClipboard(text); callback->Success(""); } - catch (loot::error &e) { + catch (loot::Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to copy plugin metadata. Details: " << e.what(); callback->Failure(e.code(), (boost::format(loc::translate("Failed to copy plugin metadata. Details: %1%")) % e.what()).str()); } @@ -369,7 +369,7 @@ namespace loot { CopyToClipboard(ss.str()); callback->Success(""); } - catch (loot::error &e) { + catch (loot::Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to copy plugin metadata. Details: " << e.what(); callback->Failure(e.code(), (boost::format(loc::translate("Failed to copy plugin metadata. Details: %1%")) % e.what()).str()); } @@ -693,7 +693,7 @@ namespace loot { gameNode["masterlist"]["revision"] = info.revision; gameNode["masterlist"]["date"] = info.date; } - catch (error &e) { + catch (Error &e) { gameNode["masterlist"]["revision"] = e.what(); gameNode["masterlist"]["date"] = e.what(); } @@ -770,7 +770,7 @@ namespace loot { callback->Success(JSON::stringify(gameNode)); } - catch (loot::error &e) { + catch (loot::Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to get game data. Details: " << e.what(); callback->Failure(e.code(), (boost::format(loc::translate("Failed to get game data. Details: %1%")) % e.what()).str()); } @@ -788,8 +788,8 @@ namespace loot { try { wasChanged = _lootState.CurrentGame().GetMasterlist().Update(_lootState.CurrentGame()); } - catch (loot::error &e) { - if (e.code() == loot::error::ok) { + catch (loot::Error &e) { + if (e.code() == loot::Error::ok) { // There was a parsing error, but roll-back was successful, so the process // should still complete. @@ -817,7 +817,7 @@ namespace loot { gameNode["masterlist"]["revision"] = info.revision; gameNode["masterlist"]["date"] = info.date; } - catch (error &e) { + catch (Error &e) { gameNode["masterlist"]["revision"] = e.what(); gameNode["masterlist"]["date"] = e.what(); } @@ -861,7 +861,7 @@ namespace loot { else callback->Success("null"); } - catch (error &e) { + catch (Error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to update the masterlist. Details: " << e.what(); callback->Failure(e.code(), (boost::format(loc::translate("Failed to update the masterlist. Details: %1%")) % e.what()).str()); } @@ -959,9 +959,9 @@ namespace loot { else callback->Success("null"); } - catch (loot::error& e) { + catch (loot::Error& e) { BOOST_LOG_TRIVIAL(error) << "Failed to sort plugins. Details: " << e.what(); - if (e.code() == error::sorting_error) { + if (e.code() == Error::sorting_error) { _lootState.CurrentGame().AppendMessage(Message(Message::error, e.what())); YAML::Node node; @@ -1059,11 +1059,11 @@ namespace loot { void QueryHandler::CopyToClipboard(const std::string& text) { #ifdef _WIN32 if (!OpenClipboard(NULL)) { - throw loot::error(loot::error::windows_error, "Failed to open the Windows clipboard."); + throw loot::Error(loot::Error::windows_error, "Failed to open the Windows clipboard."); } if (!EmptyClipboard()) { - throw loot::error(loot::error::windows_error, "Failed to empty the Windows clipboard."); + throw loot::Error(loot::Error::windows_error, "Failed to empty the Windows clipboard."); } // The clipboard takes a Unicode (ie. UTF-16) string that it then owns and must not @@ -1074,11 +1074,11 @@ namespace loot { wcscpy(wcstr, wtext.c_str()); if (SetClipboardData(CF_UNICODETEXT, wcstr) == NULL) { - throw loot::error(loot::error::windows_error, "Failed to copy metadata to the Windows clipboard."); + throw loot::Error(loot::Error::windows_error, "Failed to copy metadata to the Windows clipboard."); } if (!CloseClipboard()) { - throw loot::error(loot::error::windows_error, "Failed to close the Windows clipboard."); + throw loot::Error(loot::Error::windows_error, "Failed to close the Windows clipboard."); } #endif } diff --git a/src/tests/backend/game/game_test.h b/src/tests/backend/game/game_test.h index a5f02c59..9ed91892 100644 --- a/src/tests/backend/game/game_test.h +++ b/src/tests/backend/game/game_test.h @@ -94,10 +94,10 @@ namespace loot { TEST_P(GameTest, initShouldThrowIfGameHasAnInvalidId) { Game game; - EXPECT_THROW(game.Init(false), error); - EXPECT_THROW(game.Init(true), error); - EXPECT_THROW(game.Init(false, localPath), error); - EXPECT_THROW(game.Init(true, localPath), error); + EXPECT_THROW(game.Init(false), Error); + EXPECT_THROW(game.Init(true), Error); + EXPECT_THROW(game.Init(false, localPath), Error); + EXPECT_THROW(game.Init(true, localPath), Error); } TEST_P(GameTest, getArchiveFileExtensionShouldReturnDotBa2ForFallout4AndDotBsaForOtherGames) { @@ -113,16 +113,16 @@ namespace loot { // test autodetection fully unless on Linux. TEST_P(GameTest, initShouldThrowOnLinuxIfGamePathIsNotGiven) { Game game = Game(GetParam()); - EXPECT_THROW(game.Init(false), error); - EXPECT_THROW(game.Init(true), error); - EXPECT_THROW(game.Init(false, localPath), error); - EXPECT_THROW(game.Init(true, localPath), error); + EXPECT_THROW(game.Init(false), Error); + EXPECT_THROW(game.Init(true), Error); + EXPECT_THROW(game.Init(false, localPath), Error); + EXPECT_THROW(game.Init(true, localPath), Error); } TEST_P(GameTest, initShouldThrowOnLinuxIfLocalPathIsNotGiven) { Game game = Game(GetParam()).SetGamePath(dataPath.parent_path()); ASSERT_FALSE(boost::filesystem::exists(LootPaths::getLootDataPath() / game.FolderName())); - EXPECT_THROW(game.Init(false), error); + EXPECT_THROW(game.Init(false), Error); } // Testing on Windows will find real LOOT installs, and they shouldn't be @@ -163,7 +163,7 @@ namespace loot { game.SetGamePath(dataPath.parent_path()); if (GetParam() == Game::tes5) - EXPECT_THROW(game.RedatePlugins(), error); + EXPECT_THROW(game.RedatePlugins(), Error); else EXPECT_NO_THROW(game.RedatePlugins()); } diff --git a/src/tests/backend/game/load_order_handler_test.h b/src/tests/backend/game/load_order_handler_test.h index 3b385db9..a5edd79d 100644 --- a/src/tests/backend/game/load_order_handler_test.h +++ b/src/tests/backend/game/load_order_handler_test.h @@ -52,19 +52,19 @@ namespace loot { GameSettings game(GameSettings::autodetect); game.SetGamePath(dataPath.parent_path()); - EXPECT_THROW(loh.Init(game), error); - EXPECT_THROW(loh.Init(game), error); - EXPECT_THROW(loh.Init(game, localPath), error); - EXPECT_THROW(loh.Init(game, localPath), error); + EXPECT_THROW(loh.Init(game), Error); + EXPECT_THROW(loh.Init(game), Error); + EXPECT_THROW(loh.Init(game, localPath), Error); + EXPECT_THROW(loh.Init(game, localPath), Error); } TEST_P(LoadOrderHandlerTest, initShouldThrowIfNoGamePathIsSet) { GameSettings game(GetParam()); - EXPECT_THROW(loh.Init(game), error); - EXPECT_THROW(loh.Init(game), error); - EXPECT_THROW(loh.Init(game, localPath), error); - EXPECT_THROW(loh.Init(game, localPath), error); + EXPECT_THROW(loh.Init(game), Error); + EXPECT_THROW(loh.Init(game), Error); + EXPECT_THROW(loh.Init(game, localPath), Error); + EXPECT_THROW(loh.Init(game, localPath), Error); } #ifndef _WIN32 @@ -72,7 +72,7 @@ namespace loot { GameSettings game(GetParam()); game.SetGamePath(dataPath.parent_path()); - EXPECT_THROW(loh.Init(game), error); + EXPECT_THROW(loh.Init(game), Error); } #endif @@ -84,7 +84,7 @@ namespace loot { } TEST_P(LoadOrderHandlerTest, isPluginActiveShouldThrowIfTheHandlerHasNotBeenInitialised) { - EXPECT_THROW(loh.IsPluginActive(masterFile), error); + EXPECT_THROW(loh.IsPluginActive(masterFile), Error); } TEST_P(LoadOrderHandlerTest, isPluginActiveShouldReturnCorrectPluginStatesAfterInitialisation) { @@ -98,7 +98,7 @@ namespace loot { } TEST_P(LoadOrderHandlerTest, getLoadOrderShouldThrowIfTheHandlerHasNotBeenInitialised) { - EXPECT_THROW(loh.GetLoadOrder(), error); + EXPECT_THROW(loh.GetLoadOrder(), Error); } TEST_P(LoadOrderHandlerTest, getLoadOrderShouldReturnTheCurrentLoadOrder) { @@ -124,7 +124,7 @@ namespace loot { blankPluginDependentEsp, }); - EXPECT_THROW(loh.SetLoadOrder(std::list()), error); + EXPECT_THROW(loh.SetLoadOrder(std::list()), Error); } TEST_P(LoadOrderHandlerTest, setLoadOrderShouldSetTheLoadOrder) { diff --git a/src/tests/backend/helpers/git_helper_test.h b/src/tests/backend/helpers/git_helper_test.h index 23a7469f..0c5a5143 100644 --- a/src/tests/backend/helpers/git_helper_test.h +++ b/src/tests/backend/helpers/git_helper_test.h @@ -93,8 +93,8 @@ namespace loot { } TEST_F(GitHelperTest, callShouldThrowIfPassedANonZeroValue) { - EXPECT_THROW(git.Call(1), error); - EXPECT_THROW(git.Call(-1), error); + EXPECT_THROW(git.Call(1), Error); + EXPECT_THROW(git.Call(-1), Error); } TEST_F(GitHelperTest, setErrorMessageShouldSetTheMessageForThrownExceptions) { @@ -105,7 +105,7 @@ namespace loot { git.Call(1); ADD_FAILURE() << "An exception should have been thrown."; } - catch (error& e) { + catch (Error& e) { EXPECT_NE(nullptr, strstr(e.what(), errorMessage)); } } @@ -131,7 +131,7 @@ namespace loot { } TEST_F(GitHelperTest, isFileDifferentShouldThrowIfGivenANonRepositoryPath) { - EXPECT_THROW(GitHelper::IsFileDifferent(boost::filesystem::current_path(), "README.md"), error); + EXPECT_THROW(GitHelper::IsFileDifferent(boost::filesystem::current_path(), "README.md"), Error); } TEST_F(GitHelperTest, isFileDifferentShouldReturnFalseForAnUntrackedFile) { diff --git a/src/tests/backend/helpers/helpers_test.h b/src/tests/backend/helpers/helpers_test.h index d8b6b80f..dffb7da9 100644 --- a/src/tests/backend/helpers/helpers_test.h +++ b/src/tests/backend/helpers/helpers_test.h @@ -44,7 +44,7 @@ namespace loot { GameSettings::tes5)); TEST_P(GetCrc32Test, gettingTheCrcOfAMissingFileShouldThrow) { - EXPECT_THROW(GetCrc32(dataPath / missingEsp), error); + EXPECT_THROW(GetCrc32(dataPath / missingEsp), Error); } TEST_P(GetCrc32Test, gettingTheCrcOfAFileShouldReturnTheCorrectValue) { diff --git a/src/tests/backend/metadata/condition_grammar_test.h b/src/tests/backend/metadata/condition_grammar_test.h index 81a2ab5c..b53194e2 100644 --- a/src/tests/backend/metadata/condition_grammar_test.h +++ b/src/tests/backend/metadata/condition_grammar_test.h @@ -84,7 +84,7 @@ namespace loot { std::cend(condition), grammar, skipper, - result), error); + result), Error); } TEST_P(ConditionGrammarTest, evaluatingInvalidSyntaxShouldThrow) { @@ -95,7 +95,7 @@ namespace loot { std::cend(condition), grammar, skipper, - result), error); + result), Error); } TEST_P(ConditionGrammarTest, parsingAnEmptyConditionShouldThrow) { @@ -106,7 +106,7 @@ namespace loot { std::cend(condition), grammar, skipper, - result), error); + result), Error); } TEST_P(ConditionGrammarTest, evaluatingAnEmptyConditionShouldThrow) { @@ -117,7 +117,7 @@ namespace loot { std::cend(condition), grammar, skipper, - result), error); + result), Error); } TEST_P(ConditionGrammarTest, aFileConditionWithAPluginThatExistsShouldEvaluateToTrue) { @@ -154,7 +154,7 @@ namespace loot { std::cend(condition), grammar, skipper, - result), error); + result), Error); } TEST_P(ConditionGrammarTest, aRegexConditionWithAnInvalidRegexShouldThrow) { @@ -165,7 +165,7 @@ namespace loot { std::cend(condition), grammar, skipper, - result), error); + result), Error); } TEST_P(ConditionGrammarTest, aRegexConditionWithARegexMatchingAPluginThatExistsShouldEvaluateToTrue) { diff --git a/src/tests/backend/metadata/conditional_metadata_test.h b/src/tests/backend/metadata/conditional_metadata_test.h index d718934c..a960e217 100644 --- a/src/tests/backend/metadata/conditional_metadata_test.h +++ b/src/tests/backend/metadata/conditional_metadata_test.h @@ -79,7 +79,7 @@ namespace loot { game.SetGamePath(dataPath.parent_path()); conditionalMetadata = ConditionalMetadata("condition"); - EXPECT_THROW(conditionalMetadata.EvalCondition(game), error); + EXPECT_THROW(conditionalMetadata.EvalCondition(game), Error); } TEST_P(ConditionalMetadataTest, evalConditionShouldReturnTrueForAConditionThatIsTrue) { @@ -104,7 +104,7 @@ namespace loot { TEST_P(ConditionalMetadataTest, parseConditionShouldThrowForAnInvalidCondition) { conditionalMetadata = ConditionalMetadata("condition"); - EXPECT_THROW(conditionalMetadata.ParseCondition(), error); + EXPECT_THROW(conditionalMetadata.ParseCondition(), Error); } TEST_P(ConditionalMetadataTest, parseConditionShouldNotThrowForATrueCondition) {