mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 13:55:38 +00:00
Error: Strip trailing whitespace from Windows errors
This commit is contained in:
parent
0a63bec65c
commit
c85e743573
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cwctype>
|
||||
#include <type_traits>
|
||||
|
||||
#include "fmt/format.h"
|
||||
|
@ -99,8 +100,11 @@ void Error::SetWin32(std::string_view prefix, unsigned long err)
|
|||
m_type = Type::Win32;
|
||||
|
||||
WCHAR buf[128];
|
||||
const DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf,
|
||||
static_cast<DWORD>(std::size(buf)), nullptr);
|
||||
DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf,
|
||||
static_cast<DWORD>(std::size(buf)), nullptr);
|
||||
while (r > 0 && std::iswspace(buf[r - 1]))
|
||||
r--;
|
||||
|
||||
if (r > 0)
|
||||
{
|
||||
m_description =
|
||||
|
@ -134,8 +138,11 @@ void Error::SetHResult(std::string_view prefix, long err)
|
|||
m_type = Type::HResult;
|
||||
|
||||
WCHAR buf[128];
|
||||
const DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf,
|
||||
static_cast<DWORD>(std::size(buf)), nullptr);
|
||||
DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf,
|
||||
static_cast<DWORD>(std::size(buf)), nullptr);
|
||||
while (r > 0 && std::iswspace(buf[r - 1]))
|
||||
r--;
|
||||
|
||||
if (r > 0)
|
||||
{
|
||||
m_description = fmt::format("{}HRESULT {:08X}: {}", prefix, static_cast<unsigned>(err),
|
||||
|
|
Loading…
Reference in a new issue