winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

Decode Win32 HRESULT messages before formatting

Open starSumi opened this issue 5 months ago • 1 comments

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_WIN32 HRESULTs before formatting unknown external error messages.
  • Add a regression test for HRESULT_FROM_WIN32(ERROR_INTERNET_CANNOT_CONNECT).

Validation

  • git diff --check passed locally.
  • I could not run AppInstallerCLITests.exe locally 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

starSumi avatar Jun 23 '26 03:06 starSumi

@microsoft-github-policy-service agree

starSumi avatar Jun 23 '26 08:06 starSumi

/azp run

florelis avatar Jul 20 '26 22:07 florelis

Azure Pipelines:
Successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jul 20 '26 22:07 azure-pipelines[bot]

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.

starSumi avatar Jul 22 '26 10:07 starSumi

/azp run

starSumi avatar Jul 22 '26 10:07 starSumi

Commenter does not have sufficient privileges for PR 6321 in repo microsoft/winget-cli

azure-pipelines[bot] avatar Jul 22 '26 10:07 azure-pipelines[bot]

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.

starSumi avatar Jul 22 '26 10:07 starSumi