From ce729f8d76ef984ba692c883f38a2642d1b4f0cb Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 15 May 2025 18:15:07 +0100 Subject: [PATCH] Remove libloadorder_category() Throw errors from libloadorder as std::runtime_error instead of std::system_error. --- docs/api/reference.rst | 2 -- include/loot/exception/error_categories.h | 8 -------- src/api/exception/error_categories.cpp | 15 --------------- src/api/game/load_order_handler.cpp | 13 ++++++------- src/tests/api/interface/create_game_handle_test.h | 2 +- src/tests/api/internals/game/game_test.h | 1 - .../api/internals/game/load_order_handler_test.h | 2 +- 7 files changed, 8 insertions(+), 35 deletions(-) diff --git a/docs/api/reference.rst b/docs/api/reference.rst index e12f4f53..fa110b1d 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -105,5 +105,3 @@ LOOT uses error category objects to identify errors with codes that originate in lower-level libraries. .. doxygenfunction:: loot::esplugin_category - -.. doxygenfunction:: loot::libloadorder_category diff --git a/include/loot/exception/error_categories.h b/include/loot/exception/error_categories.h index 42773fcc..d5c005c8 100644 --- a/include/loot/exception/error_categories.h +++ b/include/loot/exception/error_categories.h @@ -37,14 +37,6 @@ namespace loot { * derived from std::error_category. */ LOOT_API const std::error_category& esplugin_category(); - -/** - * @brief Get the error category that can be used to identify system_error - * exceptions that are due to libloadorder errors. - * @returns A reference to the static object of unspecified runtime type, - * derived from std::error_category. - */ -LOOT_API const std::error_category& libloadorder_category(); } #endif diff --git a/src/api/exception/error_categories.cpp b/src/api/exception/error_categories.cpp index b4bd9521..c6035f07 100644 --- a/src/api/exception/error_categories.cpp +++ b/src/api/exception/error_categories.cpp @@ -37,25 +37,10 @@ class esplugin_category : public std::error_category { return code.category().name() == name(); } }; - -class libloadorder_category : public std::error_category { - const char* name() const noexcept override { return "libloadorder"; } - - std::string message(int) const override { return "Libloadorder error"; } - - bool equivalent(const std::error_code& code, int) const noexcept override { - return code.category().name() == name(); - } -}; } LOOT_API const std::error_category& esplugin_category() { static detail::esplugin_category instance; return instance; } - -LOOT_API const std::error_category& libloadorder_category() { - static detail::libloadorder_category instance; - return instance; -} } diff --git a/src/api/game/load_order_handler.cpp b/src/api/game/load_order_handler.cpp index 36873dde..171d246a 100644 --- a/src/api/game/load_order_handler.cpp +++ b/src/api/game/load_order_handler.cpp @@ -25,7 +25,6 @@ #include "api/game/load_order_handler.h" #include "api/helpers/logging.h" -#include "loot/exception/error_categories.h" namespace loot { unsigned int mapGameId(GameType gameType) { @@ -298,14 +297,14 @@ void LoadOrderHandler::HandleError(std::string_view operation, return; } - const char* e = nullptr; + const char* message = nullptr; std::string err; - lo_get_error_message(&e); - if (e == nullptr) { + lo_get_error_message(&message); + if (message == nullptr) { err = fmt::format( - "libloadorder failed to {}. Details could not be fetched.", operation); + "Failed to {}. libloadorder error code: {}", operation, returnCode); } else { - err = fmt::format("libloadorder failed to {}. Details: {}", operation, e); + err = fmt::format("Failed to {}. Details: {}", operation, message); } auto logger = getLogger(); @@ -313,6 +312,6 @@ void LoadOrderHandler::HandleError(std::string_view operation, logger->error(err); } - throw std::system_error(returnCode, libloadorder_category(), err); + throw std::runtime_error(err); } } diff --git a/src/tests/api/interface/create_game_handle_test.h b/src/tests/api/interface/create_game_handle_test.h index ab5d5c0b..b6466994 100644 --- a/src/tests/api/interface/create_game_handle_test.h +++ b/src/tests/api/interface/create_game_handle_test.h @@ -150,7 +150,7 @@ TEST_P( GetParam() == GameType::oblivionRemastered) { EXPECT_NO_THROW(CreateGameHandle(GetParam(), gamePath)); } else { - EXPECT_THROW(CreateGameHandle(GetParam(), gamePath), std::system_error); + EXPECT_THROW(CreateGameHandle(GetParam(), gamePath), std::runtime_error); } } #else diff --git a/src/tests/api/internals/game/game_test.h b/src/tests/api/internals/game/game_test.h index 6a3671e6..7377c2ce 100644 --- a/src/tests/api/internals/game/game_test.h +++ b/src/tests/api/internals/game/game_test.h @@ -26,7 +26,6 @@ along with LOOT. If not, see #define LOOT_TESTS_API_INTERNALS_GAME_GAME_TEST #include "api/game/game.h" -#include "loot/exception/error_categories.h" #include "tests/common_game_test_fixture.h" namespace loot { diff --git a/src/tests/api/internals/game/load_order_handler_test.h b/src/tests/api/internals/game/load_order_handler_test.h index a09e38e7..e7466b05 100644 --- a/src/tests/api/internals/game/load_order_handler_test.h +++ b/src/tests/api/internals/game/load_order_handler_test.h @@ -151,7 +151,7 @@ TEST_P(LoadOrderHandlerTest, GetParam() == GameType::oblivionRemastered) { EXPECT_NO_THROW(LoadOrderHandler(GetParam(), gamePath)); } else { - EXPECT_THROW(LoadOrderHandler(GetParam(), gamePath), std::system_error); + EXPECT_THROW(LoadOrderHandler(GetParam(), gamePath), std::runtime_error); } } #endif