Error: Strip trailing whitespace from Windows errors

This commit is contained in:
Stenzek 2024-05-12 15:20:39 +10:00
parent 0a63bec65c
commit c85e743573
No known key found for this signature in database

View file

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