refactor(libutil): add new constructor to SysError using std::error_code

Change-Id: I6150d7966442551f0b6f7a0cc9739a4f9d6c4e7e
This commit is contained in:
V. 2024-12-09 20:38:50 +04:00
parent 369e3f82f0
commit 95e088de72

View file

@ -26,6 +26,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <system_error>
namespace nix {
@ -194,6 +195,15 @@ public:
err.msg = HintFmt("%1%: %2%", Uncolored(hf.str()), strerror(errNo));
}
template<typename... Args>
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<typename... Args>
SysError(const Args & ... args)
: SysError(errno, args ...)