diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c05dde6..85181bc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,6 +221,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/app/loot_paths.h" "${CMAKE_SOURCE_DIR}/include/loot/api_decorator.h" "${CMAKE_SOURCE_DIR}/include/loot/error.h" "${CMAKE_SOURCE_DIR}/include/loot/error_categories.h" + "${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h" "${CMAKE_SOURCE_DIR}/include/loot/game_type.h" "${CMAKE_SOURCE_DIR}/include/loot/language_code.h" "${CMAKE_SOURCE_DIR}/include/loot/loot_version.h" @@ -280,6 +281,7 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h" "${CMAKE_SOURCE_DIR}/include/loot/database_interface.h" "${CMAKE_SOURCE_DIR}/include/loot/error.h" "${CMAKE_SOURCE_DIR}/include/loot/error_categories.h" + "${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h" "${CMAKE_SOURCE_DIR}/include/loot/game_type.h" "${CMAKE_SOURCE_DIR}/include/loot/language_code.h" "${CMAKE_SOURCE_DIR}/include/loot/loot_version.h" diff --git a/docs/api/Doxyfile b/docs/api/Doxyfile index 30827ce3..a092323e 100644 --- a/docs/api/Doxyfile +++ b/docs/api/Doxyfile @@ -781,7 +781,8 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = include/loot +INPUT = include/loot \ + include/loot/exception # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/docs/api/reference.rst b/docs/api/reference.rst index 532e6d57..afedbb8b 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -43,6 +43,9 @@ Interfaces Classes ======= +.. doxygenclass:: loot::CyclicInteractionError + :members: + .. doxygenclass:: loot::Error :members: diff --git a/include/loot/api.h b/include/loot/api.h index 337096bd..5a81c2ae 100644 --- a/include/loot/api.h +++ b/include/loot/api.h @@ -32,6 +32,7 @@ #include "loot/database_interface.h" #include "loot/error.h" #include "loot/error_categories.h" +#include "loot/exception/cyclic_interaction_error.h" #include "loot/game_type.h" #include "loot/loot_version.h" diff --git a/include/loot/error.h b/include/loot/error.h index 94aa0a96..c6135131 100644 --- a/include/loot/error.h +++ b/include/loot/error.h @@ -64,8 +64,6 @@ public: * repository. */ git_error = 12, - /** An error occurred while trying to sort the load order. */ - sorting_error = 14, }; /** diff --git a/include/loot/exception/cyclic_interaction_error.h b/include/loot/exception/cyclic_interaction_error.h new file mode 100644 index 00000000..6f5ba3c6 --- /dev/null +++ b/include/loot/exception/cyclic_interaction_error.h @@ -0,0 +1,41 @@ +/* LOOT + + A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and + Fallout: New Vegas. + + Copyright (C) 2012-2016 WrinklyNinja + + This file is part of LOOT. + + LOOT is free software: you can redistribute + it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + LOOT is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LOOT. If not, see + . + */ + +#ifndef LOOT_EXCEPTION_CYCLIC_INTERACTION_ERROR +#define LOOT_EXCEPTION_CYCLIC_INTERACTION_ERROR + +#include + +namespace loot { +/** + * @brief An exception class thrown if a cyclic interaction is detected when + * sorting a load order. + */ +class CyclicInteractionError : public std::runtime_error { +public: + using std::runtime_error::runtime_error; +}; +} + +#endif diff --git a/src/backend/plugin/plugin_sorter.cpp b/src/backend/plugin/plugin_sorter.cpp index b58f162a..6bce1d71 100644 --- a/src/backend/plugin/plugin_sorter.cpp +++ b/src/backend/plugin/plugin_sorter.cpp @@ -35,6 +35,7 @@ #include #include "loot/error.h" +#include "loot/exception/cyclic_interaction_error.h" #include "backend/game/game.h" #include "backend/helpers/helpers.h" @@ -79,7 +80,7 @@ public: BOOST_LOG_TRIVIAL(error) << "Cyclic interaction detected between plugins \"" << graph[source].Name() << "\" and \"" << graph[target].Name() << "\". Back cycle: " << backCycle; - throw loot::Error(loot::Error::Code::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 CyclicInteractionError((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: diff --git a/src/gui/query/sort_plugins_query.h b/src/gui/query/sort_plugins_query.h index 0bc13e88..e526b731 100644 --- a/src/gui/query/sort_plugins_query.h +++ b/src/gui/query/sort_plugins_query.h @@ -27,8 +27,10 @@ along with LOOT. If not, see #include +#include "backend/app/loot_state.h" #include "backend/helpers/json.h" #include "backend/plugin/plugin_sorter.h" +#include "loot/exception/cyclic_interaction_error.h" #include "gui/query/metadata_query.h" namespace loot { @@ -68,12 +70,11 @@ private: try { PluginSorter sorter; plugins = sorter.Sort(state_.getCurrentGame(), state_.getLanguage().GetCode()); + } catch (CyclicInteractionError& e) { + BOOST_LOG_TRIVIAL(error) << "Failed to sort plugins. Details: " << e.what(); + state_.getCurrentGame().AppendMessage(Message(MessageType::error, e.what())); } catch (Error& e) { BOOST_LOG_TRIVIAL(error) << "Failed to sort plugins. Details: " << e.what(); - if (e.code() != Error::Code::sorting_error) - throw; - - state_.getCurrentGame().AppendMessage(Message(MessageType::error, e.what())); } return plugins;