diff options
author | John Moffett <john.moff@gmail.com> | 2022-12-05 12:59:15 -0500 |
---|---|---|
committer | John Moffett <john.moff@gmail.com> | 2023-06-30 09:48:21 -0400 |
commit | c95a4432d7c9d0e5829cd802908700ba2e2c25dc (patch) | |
tree | 0f3fe9d7b7ae4653fc847918d84b0b065618b27d /src/util/syserror.cpp | |
parent | 91ccb62faab21b2b52b089cc04f3a5c1bf6989cc (diff) |
Show descriptive error messages when FileCommit fails
Only raw errno codes are logged if FileCommit fails. These are
implementation-specific, so it makes it harder to debug based on
user reports. Instead, use SysErrorString to display both the
raw int value and the descriptive message.
Diffstat (limited to 'src/util/syserror.cpp')
-rw-r--r-- | src/util/syserror.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util/syserror.cpp b/src/util/syserror.cpp index 5270f55366..bac498a23d 100644 --- a/src/util/syserror.cpp +++ b/src/util/syserror.cpp @@ -12,6 +12,12 @@ #include <cstring> #include <string> +#if defined(WIN32) +#include <windows.h> +#include <locale> +#include <codecvt> +#endif + std::string SysErrorString(int err) { char buf[1024]; @@ -33,3 +39,21 @@ std::string SysErrorString(int err) return strprintf("Unknown error (%d)", err); } } + +#if defined(WIN32) +std::string Win32ErrorString(int err) +{ + wchar_t buf[256]; + buf[0] = 0; + if(FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, + nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, ARRAYSIZE(buf), nullptr)) + { + return strprintf("%s (%d)", std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().to_bytes(buf), err); + } + else + { + return strprintf("Unknown error (%d)", err); + } +} +#endif |