diff --git a/src/api/api_database.cpp b/src/api/api_database.cpp index 354dcf87..c722a26d 100644 --- a/src/api/api_database.cpp +++ b/src/api/api_database.cpp @@ -117,21 +117,16 @@ MasterlistInfo ApiDatabase::GetMasterlistRevision(const std::string& masterlistP const bool getShortID) { MasterlistInfo apiMasterlistInfo; apiMasterlistInfo.is_modified = false; - try { - Masterlist::Info info = Masterlist::GetInfo(masterlistPath, getShortID); + Masterlist::Info info = Masterlist::GetInfo(masterlistPath, getShortID); - if (boost::ends_with(info.revision, " (edited)")) { - apiMasterlistInfo.revision_id = info.revision.substr(0, info.revision.length() - 9); - apiMasterlistInfo.revision_date = info.date.substr(0, info.date.length() - 9); - apiMasterlistInfo.is_modified = true; - } else { - apiMasterlistInfo.revision_id = info.revision; - apiMasterlistInfo.revision_date = info.date; - apiMasterlistInfo.is_modified = false; - } - } catch (Error &e) { - if (e.code() != Error::Code::ok) - throw; + if (boost::ends_with(info.revision, " (edited)")) { + apiMasterlistInfo.revision_id = info.revision.substr(0, info.revision.length() - 9); + apiMasterlistInfo.revision_date = info.date.substr(0, info.date.length() - 9); + apiMasterlistInfo.is_modified = true; + } else { + apiMasterlistInfo.revision_id = info.revision; + apiMasterlistInfo.revision_date = info.date; + apiMasterlistInfo.is_modified = false; } return apiMasterlistInfo; diff --git a/src/backend/helpers/git_helper.cpp b/src/backend/helpers/git_helper.cpp index e68f5e73..e94b732e 100644 --- a/src/backend/helpers/git_helper.cpp +++ b/src/backend/helpers/git_helper.cpp @@ -307,7 +307,7 @@ GitHelper::GitData& GitHelper::GetData() { 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::Code::ok, translate("Unknown: Git repository missing")); + throw GitStateError("Cannot check if the \"" + filename + "\" working copy is edited, Git repository missing."); } BOOST_LOG_TRIVIAL(debug) << "Existing repository found, attempting to open it."; diff --git a/src/backend/masterlist.cpp b/src/backend/masterlist.cpp index 7f40b373..6989adf5 100644 --- a/src/backend/masterlist.cpp +++ b/src/backend/masterlist.cpp @@ -26,7 +26,8 @@ #include -#include "loot/error.h" +#include "loot/exception/file_access_error.h" +#include "loot/exception/git_state_error.h" #include "backend/game/game.h" #include "backend/helpers/git_helper.h" @@ -44,10 +45,10 @@ Masterlist::Info Masterlist::GetInfo(const boost::filesystem::path& path, bool s if (!fs::exists(path)) { BOOST_LOG_TRIVIAL(info) << "Unknown masterlist revision: No masterlist present."; - throw Error(Error::Code::ok, translate("N/A: No masterlist present")); + throw FileAccessError(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::Code::ok, translate("Unknown: Git repository missing")); + throw GitStateError(translate("Unknown: Git repository missing")); } BOOST_LOG_TRIVIAL(debug) << "Existing repository found, attempting to open it."; @@ -263,7 +264,7 @@ bool Masterlist::Update(const boost::filesystem::path& path, const std::string& } while (parsingFailed); if (!parsingError.empty()) - throw Error(Error::Code::ok, parsingError); //Throw an OK because the process still completed in a successful state. + AppendMessage(Message(MessageType::error, parsingError)); return true; } diff --git a/src/backend/plugin/plugin_sorter.cpp b/src/backend/plugin/plugin_sorter.cpp index 6bce1d71..abb54230 100644 --- a/src/backend/plugin/plugin_sorter.cpp +++ b/src/backend/plugin/plugin_sorter.cpp @@ -48,6 +48,8 @@ typedef boost::graph_traits::vertex_iterator vertex_it; typedef boost::graph_traits::edge_descriptor edge_t; typedef boost::graph_traits::edge_iterator edge_it; +class PathFoundException : public std::exception {}; + class CycleDetector : public boost::dfs_visitor<> { public: void tree_edge(edge_t edge, const PluginGraph& graph) { @@ -93,7 +95,7 @@ public: inline void discover_vertex(vertex_t vertex, const PluginGraph& graph) { if (vertex == target) - throw Error(Error::Code::ok, "Found a path."); + throw PathFoundException(); } private: @@ -248,8 +250,7 @@ void PluginSorter::CheckForCycles() const { bool PluginSorter::EdgeCreatesCycle(const vertex_t& fromVertex, const vertex_t& toVertex) const { try { boost::breadth_first_search(graph_, toVertex, visitor(PathDetector(fromVertex)).vertex_index_map(vertexIndexMap_)); - } catch (Error& e) { - if (e.code() == Error::Code::ok) + } catch (PathFoundException& e) { return true; } return false; diff --git a/src/gui/query/update_masterlist_query.h b/src/gui/query/update_masterlist_query.h index e3d19517..1d40867f 100644 --- a/src/gui/query/update_masterlist_query.h +++ b/src/gui/query/update_masterlist_query.h @@ -51,18 +51,9 @@ private: try { return game_.GetMasterlist().Update(game_); } catch (Error &e) { - if (e.code() == Error::Code::ok) { - // There was a parsing error, but roll-back was successful, so the - // process should still complete. - game_.GetMasterlist().AppendMessage(Message(MessageType::error, e.what())); - return true; - } else { - // Error wasn't a parsing error. Need to try parsing masterlist if it - // exists. - try { - game_.GetMasterlist().Load(game_.MasterlistPath()); - } catch (...) {} - } + try { + game_.GetMasterlist().Load(game_.MasterlistPath()); + } catch (...) {} throw; } } diff --git a/src/tests/api/database_interface_test.h b/src/tests/api/database_interface_test.h index 6fa028b1..7483a8bd 100644 --- a/src/tests/api/database_interface_test.h +++ b/src/tests/api/database_interface_test.h @@ -209,19 +209,19 @@ TEST_P(DatabaseInterfaceTest, updateMasterlistShouldSucceedIfCalledRepeatedlyBut EXPECT_TRUE(boost::filesystem::exists(masterlistPath)); } -TEST_P(DatabaseInterfaceTest, getMasterlistRevisionShouldSucceedIfNoMasterlistIsPresent) { +TEST_P(DatabaseInterfaceTest, getMasterlistRevisionShouldThrowIfNoMasterlistIsPresent) { MasterlistInfo info; - EXPECT_NO_THROW(info = db_->GetMasterlistRevision(masterlistPath.string(), false)); + EXPECT_THROW(info = db_->GetMasterlistRevision(masterlistPath.string(), false), FileAccessError); EXPECT_TRUE(info.revision_id.empty()); EXPECT_TRUE(info.revision_date.empty()); EXPECT_FALSE(info.is_modified); } -TEST_P(DatabaseInterfaceTest, getMasterlistRevisionShouldSucceedIfANonVersionControlledMasterlistIsPresent) { +TEST_P(DatabaseInterfaceTest, getMasterlistRevisionShouldThrowIfANonVersionControlledMasterlistIsPresent) { ASSERT_NO_THROW(GenerateMasterlist()); MasterlistInfo info; - EXPECT_NO_THROW(info = db_->GetMasterlistRevision(masterlistPath.string(), false)); + EXPECT_THROW(info = db_->GetMasterlistRevision(masterlistPath.string(), false), GitStateError); EXPECT_TRUE(info.revision_id.empty()); EXPECT_TRUE(info.revision_date.empty()); EXPECT_FALSE(info.is_modified); diff --git a/src/tests/backend/helpers/git_helper_test.h b/src/tests/backend/helpers/git_helper_test.h index e175aeca..f70fb333 100644 --- a/src/tests/backend/helpers/git_helper_test.h +++ b/src/tests/backend/helpers/git_helper_test.h @@ -29,7 +29,7 @@ along with LOOT. If not, see #include -#include "loot/error.h" +#include "loot/exception/git_state_error.h" namespace loot { namespace test { @@ -119,7 +119,7 @@ TEST_F(GitHelperTest, isRepositoryShouldReturnFalseForRepositorySubdirectory) { } 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"), GitStateError); } TEST_F(GitHelperTest, isFileDifferentShouldReturnFalseForAnUntrackedFile) {