Add Api::fail() failure factory
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
0e0f8915e9
commit
a2de8c63ce
1 file changed
+11
@@ -92,6 +92,17 @@ namespace Echoion::Api
|
||||
template <typename T>
|
||||
using Result = Void::Result::Result<T, Error>;
|
||||
|
||||
// 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<Error> 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
|
||||
|
||||
Reference in new issue
Block a user