18#include <system_error>
23# include <errhandlingapi.h>
35 std::error_code errorCode;
36 std::string errorDetails;
38 void anchor()
override;
67 , errorCode(errorCode)
68 , errorDetails(errorDetails)
76 template<
typename...
Args>
96 template<
typename...
Args>
102 const std::error_code ec() const &
107 bool is(std::errc e)
const
109 return errorCode == e;
112 template<std::same_as<std::errc>... Rest>
113 bool is(std::errc e, Rest... rest)
const
115 return is(e) || (is(rest) || ...);
155template<
typename Fields, auto field>
156 requires std::is_member_object_pointer_v<
decltype(field)>
164 using NativeCode = std::remove_cvref_t<decltype(std::declval<Fields &>().*field)>;
170 template<
typename...
Args>
174 DisambigVarArgs{}, Fields::toErrorCode(code), Fields::renderError(code), std::forward<
Args>(args)...)
197 template<
typename...
Args>
209 requires std::invocable<
decltype(mkHintFmt)> && std::same_as<std::invoke_result_t<
decltype(mkHintFmt)>,
HintFmt>
221 static std::pair<NativeCode, HintFmt> captureAmbientError(
auto && mkHintFmt)
223 NativeCode e = Fields::ambientError();
224 return {e, mkHintFmt()};
254 return std::make_error_code(
static_cast<std::errc
>(code));
262 return strerror(code);
282class SysError final :
public CloneableError<SysError, NativeCodeSystemError<SysErrorFields, &SysErrorFields::errNo>>
284 void anchor()
override;
287 using CloneableError::CloneableError;
305 static DWORD ambientError()
307 return GetLastError();
313 static std::error_code toErrorCode(DWORD code)
315 return std::error_code(code, std::system_category());
321 static std::string renderError(DWORD code);
330class WinError :
public CloneableError<WinError, NativeCodeSystemError<WinErrorFields, &WinErrorFields::lastError>>
332 void anchor()
override;
335 using CloneableError::CloneableError;
std::string message() const
Definition error.hh:192
Definition system-error.hh:158
NativeCodeSystemError(Args &&... args)
Definition system-error.hh:198
NativeCodeSystemError(NativeCode code, const HintFmt &hf)
Definition system-error.hh:185
NativeCodeSystemError(NativeCode code, Args &&... args)
Definition system-error.hh:171
NativeCodeSystemError(auto &&mkHintFmt)
Definition system-error.hh:208
Definition system-error.hh:283
SystemError(DisambigHintFmt, std::error_code errorCode, std::string_view errorDetails, const HintFmt &hf)
Definition system-error.hh:65
SystemError(std::error_code errorCode, Args &&... args)
Definition system-error.hh:97
SystemError(DisambigVarArgs, std::error_code errorCode, std::string_view errorDetails, Args &&... args)
Definition system-error.hh:77
SystemError(std::error_code errorCode, const HintFmt &hf)
Definition system-error.hh:87
This file defines two main structs/classes used in nix error handling.
Definition system-error.hh:238
static int ambientError()
Definition system-error.hh:244
static std::string renderError(int code)
Definition system-error.hh:260
static std::error_code toErrorCode(int code)
Definition system-error.hh:252
Definition system-error.hh:49
Definition system-error.hh:58
NativeSysError::NativeCode NativeError
Definition system-error.hh:359
SysError NativeSysError
Definition system-error.hh:347