mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user