From 95e088de72be378bef6b379d954dd9f5cea87e6b Mon Sep 17 00:00:00 2001 From: vigress8 Date: Mon, 9 Dec 2024 20:38:50 +0400 Subject: [PATCH] refactor(libutil): add new constructor to `SysError` using `std::error_code` Change-Id: I6150d7966442551f0b6f7a0cc9739a4f9d6c4e7e --- lix/libutil/error.hh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lix/libutil/error.hh b/lix/libutil/error.hh index 451319494..a81f3f9cd 100644 --- a/lix/libutil/error.hh +++ b/lix/libutil/error.hh @@ -26,6 +26,7 @@ #include #include #include +#include namespace nix { @@ -194,6 +195,15 @@ public: err.msg = HintFmt("%1%: %2%", Uncolored(hf.str()), strerror(errNo)); } + template + SysError(std::error_code ec, const Args & ... args) + : Error("") + { + errNo = ec.value(); + auto hf = HintFmt(args...); + err.msg = HintFmt("%1%: %2%", Uncolored(hf.str()), ec.message()); + } + template SysError(const Args & ... args) : SysError(errno, args ...)