diff --git a/include/echoion/api/base/Types.hpp b/include/echoion/api/base/Types.hpp index 5577a8f..d0eb393 100644 --- a/include/echoion/api/base/Types.hpp +++ b/include/echoion/api/base/Types.hpp @@ -92,6 +92,17 @@ namespace Echoion::Api template using Result = Void::Result::Result; + // Concise failure factory: `return Api::fail(ErrorCode::X, "msg")` instead + // of `return std::unexpected(Api::Error(ErrorCode::X, "msg"))`. Carries the + // domain ErrorCode, so it cannot defer to Void::Result::fail (which builds a + // code-less Void::Result::Error). + [[nodiscard]] inline std::unexpected fail(ErrorCode code, + std::string_view message, + std::string_view source = "") + { + return std::unexpected(Error(code, message, source)); + } + enum class LogLevel : uint8_t { Debug = 0, Info, Warning, Error, Critical }; inline constexpr std::string LogLevelToString(const LogLevel level) noexcept