Decode Win32 HRESULT messages before formatting
Summary
Fixes microsoft/winget-cli#6319.
When a Win32 error is wrapped as an HRESULT via HRESULT_FROM_WIN32, GetUserPresentableMessageForHR currently passes the full HRESULT value to std::system_category().message(...). For errors such as 0x80072efd (ERROR_INTERNET_CANNOT_CONNECT), this can render as unknown error instead of the underlying Win32/WinINet message.
This change decodes FACILITY_WIN32 HRESULTs with HRESULT_CODE(hr) before asking std::system_category for the message.
Changes
- Decode
FACILITY_WIN32HRESULTs before formatting unknown external error messages. - Add a regression test for
HRESULT_FROM_WIN32(ERROR_INTERNET_CANNOT_CONNECT).
Validation
git diff --checkpassed locally.- I could not run
AppInstallerCLITests.exelocally because this environment does not have Visual Studio/MSBuild or an already-built test binary available.
Opened as draft for maintainer feedback and CI validation.
Microsoft Reviewers: Open in CodeFlow
@microsoft-github-policy-service agree
/azp run
Azure Pipelines:
Successfully started running 1 pipeline(s).
Follow-up: I found the cause of the previous x64 and x86 test failures. On MSVC, std::system_category().message(12029) and std::system_category().message(0x80072efd) both return unknown error, so decoding the HRESULT alone does not produce a WinINet message.
This update retrieves the localized message from wininet.dll for WinINet-range codes, uses the same helper in HResultInformation::GetDescription(), and extends the regression test to cover both user-facing paths.
Local validation: git diff --check passed, and an isolated MSVC probe verified the message-table behavior. I could not run AppInstallerCLITests locally because the first-time vcpkg registry fetch was interrupted before its historical port trees were available; the refreshed PR CI is queued for the x64 and x86 tests.
/azp run
Commenter does not have sufficient privileges for PR 6321 in repo microsoft/winget-cli
Azure reports that I do not have permission to queue the x64/x86 pipeline for the updated head eefe8e7. @florelis, could you please rerun it when convenient?
Evidence: the prior test failure was caused by the system-category assumption. This head now reads the WinINet message table and covers both user-facing formatting paths.