aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc
diff options
context:
space:
mode:
Diffstat (limited to 'backend/include/rcc')
-rw-r--r--backend/include/rcc/Support/Error.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/backend/include/rcc/Support/Error.h b/backend/include/rcc/Support/Error.h
new file mode 100644
index 0000000..3d50b46
--- /dev/null
+++ b/backend/include/rcc/Support/Error.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef RCC_SUPPORT_ERROR_H
+#define RCC_SUPPORT_ERROR_H
+
+#include <cstdint>
+#include <expected>
+#include <string>
+#include <string_view>
+#include <utility>
+
+namespace rcc {
+
+enum class ErrorCode : std::uint8_t {
+ InvalidArgument,
+ ParseError,
+ VerificationError,
+ Unsupported,
+ IoError,
+ InternalError,
+};
+
+[[nodiscard]] std::string_view getErrorCodeName(ErrorCode Code) noexcept;
+
+class Error final {
+public:
+ Error(ErrorCode Code, std::string Message);
+
+ [[nodiscard]] ErrorCode code() const noexcept {
+ return Code;
+ }
+ [[nodiscard]] std::string_view message() const noexcept {
+ return Message;
+ }
+
+private:
+ ErrorCode Code;
+ std::string Message;
+};
+
+template <typename ValueT> using Expected = std::expected<ValueT, Error>;
+
+[[nodiscard]] inline std::unexpected<Error> makeUnexpected(ErrorCode Code, std::string Message) {
+ return std::unexpected<Error>(Error(Code, std::move(Message)));
+}
+
+} // namespace rcc
+
+#endif // RCC_SUPPORT_ERROR_H