Remove libloadorder_category()

Throw errors from libloadorder as std::runtime_error instead of std::system_error.
This commit is contained in:
Oliver Hamlet
2025-06-08 17:58:27 +01:00
parent 2b0eec9929
commit 05c984c769
12 changed files with 6 additions and 167 deletions
@@ -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;
}
}
-9
View File
@@ -16,7 +16,6 @@ constexpr std::string_view CYCLIC_ERROR_PREFIX = "CyclicInteractionError: "sv;
constexpr std::string_view UNDEFINED_GROUP_ERROR_PREFIX =
"UndefinedGroupError: "sv;
constexpr std::string_view ESPLUGIN_ERROR_PREFIX = "EspluginError: "sv;
constexpr std::string_view LIBLOADORDER_ERROR_PREFIX = "LibloadorderError: "sv;
constexpr std::string_view INVALID_ARGUMENT_PREFIX = "InvalidArgument: "sv;
bool startsWith(std::string_view str, std::string_view prefix) {
@@ -143,14 +142,6 @@ std::exception_ptr mapError(const ::rust::Error& error) {
return std::make_exception_ptr(
std::system_error(code, esplugin_category(), details));
} else if (startsWith(error.what(), LIBLOADORDER_ERROR_PREFIX)) {
const auto [code, details] =
parseSystemError(std::string_view(error.what())
.substr(LIBLOADORDER_ERROR_PREFIX.size()));
return std::make_exception_ptr(
std::system_error(code, libloadorder_category(), details));
} else if (startsWith(error.what(), INVALID_ARGUMENT_PREFIX)) {
return std::make_exception_ptr(
std::invalid_argument(getErrorSuffix(error.what())));
+3 -18
View File
@@ -44,7 +44,6 @@ impl std::fmt::Display for VerboseError {
Self::SystemError(e) => {
let prefix = match e.category() {
SystemErrorCategory::Esplugin => "EspluginError",
SystemErrorCategory::Libloadorder => "LibloadorderError",
_ => "UnknownCategoryError",
};
write!(f, "{}: {}: {}", prefix, e.code(), e.message())
@@ -64,13 +63,14 @@ variant_box_from_error!(LoadMetadataError, VerboseError::Other);
variant_box_from_error!(WriteMetadataError, VerboseError::Other);
variant_box_from_error!(ConditionEvaluationError, VerboseError::Other);
variant_box_from_error!(MetadataRetrievalError, VerboseError::Other);
variant_box_from_error!(LoadOrderError, VerboseError::Other);
variant_box_from_error!(LoadOrderStateError, VerboseError::Other);
impl From<GameHandleCreationError> for VerboseError {
fn from(value: GameHandleCreationError) -> Self {
match value {
GameHandleCreationError::LoadOrderError(e) => e.into(),
GameHandleCreationError::NotADirectory(_) => Self::InvalidArgument(value.to_string()),
_ => Self::Other(Box::new(value)),
GameHandleCreationError::LoadOrderError(_) | _ => Self::Other(Box::new(value)),
}
}
}
@@ -102,21 +102,6 @@ impl From<SortPluginsError> for VerboseError {
}
}
impl From<LoadOrderStateError> for VerboseError {
fn from(value: LoadOrderStateError) -> Self {
match value {
LoadOrderStateError::LoadOrderError(e) => e.into(),
LoadOrderStateError::DatabaseLockPoisoned | _ => Self::Other(Box::new(value)),
}
}
}
impl From<LoadOrderError> for VerboseError {
fn from(value: LoadOrderError) -> Self {
Self::SystemError(SystemError::from(value))
}
}
impl From<GroupsPathError> for VerboseError {
fn from(value: GroupsPathError) -> Self {
match value {
@@ -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