summaryrefslogtreecommitdiff
path: root/src/config/shared/ConfigErrors.hpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-04-28 15:56:07 +0100
committerGitHub <noreply@github.com>2026-04-28 15:56:07 +0100
commit98fbbafef78057c818fb02b15c27e38ad2f5b5bc (patch)
treec62aa1eae704e7595d58f7edeb3804e8bfd0099d /src/config/shared/ConfigErrors.hpp
parentd4c6ff434c5c7aa66bc7c28e5ce336d2a694bfcc (diff)
config/errors: Report and categorize errors properly for actions (#14192)
Makes all errors categorized, some not displayed, some displayed. All errors can be obtained after hl.dispatch()
Diffstat (limited to 'src/config/shared/ConfigErrors.hpp')
-rw-r--r--src/config/shared/ConfigErrors.hpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/config/shared/ConfigErrors.hpp b/src/config/shared/ConfigErrors.hpp
new file mode 100644
index 00000000..b6723400
--- /dev/null
+++ b/src/config/shared/ConfigErrors.hpp
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <expected>
+#include <cstdint>
+#include <string>
+#include <utility>
+
+namespace Config {
+ enum class eConfigErrorLevel : uint8_t {
+ SILENT = 0,
+ INFO,
+ WARNING,
+ ERROR,
+ };
+
+ enum class eConfigErrorCode : uint8_t {
+ UNKNOWN = 0,
+ INVALID_ARGUMENT,
+ NOT_FOUND,
+ NO_TARGET,
+ INVALID_STATE,
+ UNAVAILABLE,
+ EXECUTION_FAILED,
+ LUA_ERROR,
+ INTERNAL,
+ };
+
+ struct SConfigError {
+ SConfigError() = default;
+ SConfigError(std::string msg, eConfigErrorLevel lvl = eConfigErrorLevel::ERROR, eConfigErrorCode c = eConfigErrorCode::UNKNOWN) :
+ message(std::move(msg)), level(lvl), code(c) {}
+ SConfigError(const char* msg) : message(msg ? msg : "") {}
+
+ std::string message;
+ eConfigErrorLevel level = eConfigErrorLevel::ERROR;
+ eConfigErrorCode code = eConfigErrorCode::UNKNOWN;
+ };
+
+ using ErrorResult = std::expected<void, SConfigError>;
+
+ inline const char* toString(eConfigErrorLevel level) {
+ switch (level) {
+ case eConfigErrorLevel::SILENT: return "silent";
+ case eConfigErrorLevel::INFO: return "info";
+ case eConfigErrorLevel::WARNING: return "warning";
+ case eConfigErrorLevel::ERROR: return "error";
+ }
+ return "unknown";
+ }
+
+ inline const char* toString(eConfigErrorCode code) {
+ switch (code) {
+ case eConfigErrorCode::UNKNOWN: return "unknown";
+ case eConfigErrorCode::INVALID_ARGUMENT: return "invalid_argument";
+ case eConfigErrorCode::NOT_FOUND: return "not_found";
+ case eConfigErrorCode::NO_TARGET: return "no_target";
+ case eConfigErrorCode::INVALID_STATE: return "invalid_state";
+ case eConfigErrorCode::UNAVAILABLE: return "unavailable";
+ case eConfigErrorCode::EXECUTION_FAILED: return "execution_failed";
+ case eConfigErrorCode::LUA_ERROR: return "lua_error";
+ case eConfigErrorCode::INTERNAL: return "internal";
+ }
+ return "unknown";
+ }
+
+ inline std::unexpected<SConfigError> configError(std::string message, eConfigErrorLevel level = eConfigErrorLevel::ERROR, eConfigErrorCode code = eConfigErrorCode::UNKNOWN) {
+ return std::unexpected(SConfigError{std::move(message), level, code});
+ }
+}