Expose loot-condition-interpreter error codes to callers

Make ConditionSyntaxError extend from system_error instead of directly from runtime_error, so that callers can use the exception's code to distinguish between different causes.
This commit is contained in:
Oliver Hamlet
2024-09-13 20:25:16 +01:00
parent 11f7f0415a
commit 6726532a40
4 changed files with 27 additions and 3 deletions
+15
View File
@@ -47,6 +47,16 @@ class libloadorder_category : public std::error_category {
return code.category().name() == name();
}
};
class loot_condition_interpreter_category : public std::error_category {
const char* name() const noexcept override { return "loot condition interpreter"; }
std::string message(int) const override { return "loot condition interpreter 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() {
@@ -58,4 +68,9 @@ LOOT_API const std::error_category& libloadorder_category() {
static detail::libloadorder_category instance;
return instance;
}
LOOT_API const std::error_category& loot_condition_interpreter_category() {
static detail::loot_condition_interpreter_category instance;
return instance;
}
}
+2 -1
View File
@@ -29,6 +29,7 @@
#include "api/helpers/crc.h"
#include "api/helpers/logging.h"
#include "loot/exception/condition_syntax_error.h"
#include "loot/exception/error_categories.h"
namespace loot {
void HandleError(const std::string operation, int returnCode) {
@@ -50,7 +51,7 @@ void HandleError(const std::string operation, int returnCode) {
logger->error(err);
}
throw ConditionSyntaxError(err);
throw ConditionSyntaxError(returnCode, loot_condition_interpreter_category(), err);
}
int mapGameType(GameType gameType) {