From 18e4cf9b80af129394e5e11af721b8e9103fe11d Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Mon, 13 May 2019 09:43:18 +0300 Subject: [PATCH 1/2] Prefix unknown error's code with 0x, and log FormaMessage's error code --- src/common/log.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/log.cpp b/src/common/log.cpp index 653c35cc3b..838e526a7e 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -1075,9 +1075,11 @@ static const wxChar* GetSysErrorMsg(wxChar* szBuf, size_t sizeBuf, unsigned long NULL ) == 0 ) { + wxLogDebug(wxS("FormatMessage failed with error 0x%lx in %s"), + GetLastError(), __WXFUNCTION__ ? __WXFUNCTION__ : ""); // if this happens, something is seriously wrong, so don't use _() here // for safety - wxSprintf(szBuf, wxS("unknown error %lx"), nErrCode); + wxSprintf(szBuf, wxS("unknown error 0x%lx"), nErrCode); return szBuf; } From d2eec4bd90f145917a9afbebdf7cab897ee77012 Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Fri, 10 May 2019 17:15:53 +0300 Subject: [PATCH 2/2] Fix occassionally failing FormatMessage call Call FormatMessage with the IGNORE_INSERTS flag. Without the flag, the FormatMessage() call will fail when the error message contains inserts (such as %1), as we are not providing any arguments. Various Windows system error messages contain inserts; e.g. error 193. See also: https://devblogs.microsoft.com/oldnewthing/20071128-00/?p=24353 --- src/common/log.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/log.cpp b/src/common/log.cpp index 838e526a7e..fe169a6b45 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -1066,7 +1066,8 @@ static const wxChar* GetSysErrorMsg(wxChar* szBuf, size_t sizeBuf, unsigned long LPVOID lpMsgBuf; if ( ::FormatMessage ( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, nErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),