mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Add UndefinedGroupError for better sorting exception handling
This commit is contained in:
@@ -198,6 +198,7 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/file_access_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/undefined_group_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/game_type.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/log_level.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/message_type.h"
|
||||
|
||||
@@ -96,6 +96,9 @@ Exceptions
|
||||
.. doxygenclass:: loot::FileAccessError
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::UndefinedGroupError
|
||||
:members:
|
||||
|
||||
Error Categories
|
||||
================
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "loot/exception/error_categories.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "loot/exception/git_state_error.h"
|
||||
#include "loot/exception/undefined_group_error.h"
|
||||
#include "loot/game_interface.h"
|
||||
#include "loot/loot_version.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/* 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_UNDEFINED_GROUP_ERROR
|
||||
#define LOOT_EXCEPTION_UNDEFINED_GROUP_ERROR
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace loot {
|
||||
/**
|
||||
* @brief An exception class thrown if group is referenced but is undefined.
|
||||
*/
|
||||
class UndefinedGroupError : public std::runtime_error {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct an exception detailing a plugin graph cycle.
|
||||
* @param firstPlugin A plugin in the cycle.
|
||||
* @param lastPlugin Another plugin in the cycle.
|
||||
* @param backCycle A string describing the path from lastPlugin to
|
||||
* firstPlugin.
|
||||
*/
|
||||
UndefinedGroupError(const std::string& groupName) :
|
||||
std::runtime_error("The group \"" + groupName + "\" does not exist"),
|
||||
groupName_(groupName) {}
|
||||
|
||||
/**
|
||||
* Get the name of the undefined group.
|
||||
* @return A group name.
|
||||
*/
|
||||
std::string getGroupName() { return groupName_; }
|
||||
|
||||
private:
|
||||
const std::string groupName_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <boost/graph/depth_first_search.hpp>
|
||||
|
||||
#include "loot/exception/cyclic_interaction_error.h"
|
||||
#include "loot/exception/undefined_group_error.h"
|
||||
|
||||
namespace loot {
|
||||
typedef boost::adjacency_list<boost::vecS,
|
||||
@@ -104,7 +105,7 @@ std::unordered_map<std::string, std::unordered_set<std::string>> GetTransitiveAf
|
||||
for (const auto& otherGroupName : group.GetAfterGroups()) {
|
||||
auto otherVertex = groupVertices.find(otherGroupName);
|
||||
if (otherVertex == groupVertices.end()) {
|
||||
throw std::invalid_argument("The group \"" + otherGroupName + "\" does not exist");
|
||||
throw UndefinedGroupError(otherGroupName);
|
||||
}
|
||||
|
||||
auto vertex = groupVertices[group.GetName()];
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "api/metadata/condition_evaluator.h"
|
||||
#include "api/sorting/group_sort.h"
|
||||
#include "loot/exception/cyclic_interaction_error.h"
|
||||
#include "loot/exception/undefined_group_error.h"
|
||||
|
||||
using std::list;
|
||||
using std::string;
|
||||
@@ -266,8 +267,7 @@ void PluginSorter::AddPluginVertices(Game& game) {
|
||||
PluginSortingData& plugin = graph_[vertex];
|
||||
auto groupsIt = groups.find(plugin.GetGroup());
|
||||
if (groupsIt == groups.end()) {
|
||||
throw std::invalid_argument("The group \"" + plugin.GetGroup() +
|
||||
"\" set for plugin \"" + plugin.GetName() + "\" does not exist.");
|
||||
throw UndefinedGroupError(plugin.GetGroup());
|
||||
}
|
||||
else {
|
||||
plugin.SetAfterGroupPlugins(groupsIt->second);
|
||||
|
||||
@@ -30,6 +30,7 @@ along with LOOT. If not, see
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "loot/exception/cyclic_interaction_error.h"
|
||||
#include "loot/exception/undefined_group_error.h"
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
@@ -52,7 +53,7 @@ TEST(GetTransitiveAfterGroups, shouldThrowIfAnAfterGroupDoesNotExist) {
|
||||
Group("b", std::unordered_set<std::string>({ "a" }))
|
||||
});
|
||||
|
||||
EXPECT_THROW(GetTransitiveAfterGroups(groups), std::invalid_argument);
|
||||
EXPECT_THROW(GetTransitiveAfterGroups(groups), UndefinedGroupError);
|
||||
}
|
||||
|
||||
TEST(GetTransitiveAfterGroups, shouldThrowIfAfterGroupsAreCyclic) {
|
||||
|
||||
@@ -28,6 +28,7 @@ along with LOOT. If not, see
|
||||
#include "api/sorting/plugin_sorter.h"
|
||||
|
||||
#include "loot/exception/cyclic_interaction_error.h"
|
||||
#include "loot/exception/undefined_group_error.h"
|
||||
#include "tests/common_game_test_fixture.h"
|
||||
|
||||
namespace loot {
|
||||
@@ -207,7 +208,7 @@ TEST_P(PluginSorterTest, sortingShouldThrowIfAPluginHasAGroupThatDoesNotExist) {
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
EXPECT_THROW(ps.Sort(game_), std::invalid_argument);
|
||||
EXPECT_THROW(ps.Sort(game_), UndefinedGroupError);
|
||||
}
|
||||
|
||||
TEST_P(PluginSorterTest, sortingShouldThrowIfAddingTwoGroupEdgesIntroducesACycle) {
|
||||
|
||||
Reference in New Issue
Block a user