Replace sorting_error error code

With a new CyclicInteractionError exception class
This commit is contained in:
Oliver Hamlet
2016-10-08 12:21:06 +01:00
parent 711ba9b59d
commit 1d147aee02
8 changed files with 56 additions and 8 deletions
+2
View File
@@ -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"
+2 -1
View File
@@ -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
+3
View File
@@ -43,6 +43,9 @@ Interfaces
Classes
=======
.. doxygenclass:: loot::CyclicInteractionError
:members:
.. doxygenclass:: loot::Error
:members:
+1
View File
@@ -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"
-2
View File
@@ -64,8 +64,6 @@ public:
* repository.
*/
git_error = 12,
/** An error occurred while trying to sort the load order. */
sorting_error = 14,
};
/**
@@ -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
<https://www.gnu.org/licenses/>.
*/
#ifndef LOOT_EXCEPTION_CYCLIC_INTERACTION_ERROR
#define LOOT_EXCEPTION_CYCLIC_INTERACTION_ERROR
#include <stdexcept>
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
+2 -1
View File
@@ -35,6 +35,7 @@
#include <boost/log/trivial.hpp>
#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:
+5 -4
View File
@@ -27,8 +27,10 @@ along with LOOT. If not, see
#include <boost/locale.hpp>
#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;