From a2de8c63ce7a8f4a0bd3ef018418a50ba6b6e9d2 Mon Sep 17 00:00:00 2001 From: faumaray Date: Mon, 22 Jun 2026 22:07:18 +0300 Subject: [PATCH] Add Api::fail() failure factory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Api::fail(ErrorCode, msg, src="") → std::unexpected(Error(...)), a concise replacement for the verbose std::unexpected(Api::Error(...)) pattern. Keeps the domain ErrorCode (so it can't defer to Void::Result::fail). Co-Authored-By: Claude Opus 4.8 --- include/echoion/api/base/Types.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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