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.
This commit is contained in:
John Moffett
2022-12-05 12:59:15 -05:00
parent 91ccb62faa
commit c95a4432d7
4 changed files with 35 additions and 17 deletions

View File

@@ -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