diff --git a/src/AppInstallerCLITests/Errors.cpp b/src/AppInstallerCLITests/Errors.cpp index 57a7494451..1654f8d38d 100644 --- a/src/AppInstallerCLITests/Errors.cpp +++ b/src/AppInstallerCLITests/Errors.cpp @@ -3,6 +3,7 @@ #include "pch.h" #include "TestCommon.h" #include +#include using namespace AppInstaller; using namespace AppInstaller::Utility; @@ -17,3 +18,18 @@ TEST_CASE("EnsureSortedErrorList", "[errors]") REQUIRE(errors[i]->Value() > errors[i - 1]->Value()); } } + +TEST_CASE("Win32HResultMessageUsesWin32Code", "[errors]") +{ + constexpr HRESULT internetCannotConnect = HRESULT_FROM_WIN32(ERROR_INTERNET_CANNOT_CONNECT); + const std::string message = GetUserPresentableMessage(internetCannotConnect); + const std::string expectedSystemMessage = std::system_category().message(ERROR_INTERNET_CANNOT_CONNECT); + const std::string hresultSystemMessage = std::system_category().message(internetCannotConnect); + + INFO(message); + INFO(expectedSystemMessage); + INFO(hresultSystemMessage); + REQUIRE(message.find("0x80072efd") != std::string::npos); + REQUIRE(message.find(expectedSystemMessage) != std::string::npos); + REQUIRE(message.find(hresultSystemMessage) == std::string::npos); +} \ No newline at end of file diff --git a/src/AppInstallerSharedLib/Errors.cpp b/src/AppInstallerSharedLib/Errors.cpp index f91e2fc621..e0407f9027 100644 --- a/src/AppInstallerSharedLib/Errors.cpp +++ b/src/AppInstallerSharedLib/Errors.cpp @@ -361,7 +361,8 @@ namespace AppInstaller } else { - strstr << std::system_category().message(hr); + strstr << std::system_category().message( + HRESULT_FACILITY(hr) == FACILITY_WIN32 ? HRESULT_CODE(hr) : hr); } } } @@ -498,4 +499,4 @@ namespace AppInstaller return result; } } -} +} \ No newline at end of file