Skip to content

Commit

Permalink
Fail gracefully when error reporting is suppressed (#1386)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Jan 16, 2024
1 parent 25a14f8 commit 2bfcd75
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions strings/base_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ WINRT_EXPORT namespace winrt
}

com_ptr<impl::IErrorInfo> info;
WINRT_VERIFY_(0, WINRT_IMPL_GetErrorInfo(0, info.put_void()));
WINRT_VERIFY(info.try_as(m_info));
WINRT_IMPL_GetErrorInfo(0, info.put_void());
info.try_as(m_info);
}

static hresult verify_error(hresult const code) noexcept
Expand Down
17 changes: 17 additions & 0 deletions test/test/suppress_error_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "pch.h"
#include <roerrorapi.h>

TEST_CASE("suppress_error_info")
{
winrt::check_hresult(RoSetErrorReportingFlags(RO_ERROR_REPORTING_SUPPRESSSETERRORINFO));

// Since the error information is suppressed, the best we can hope for is that C++/WinRT
// will provide a generic message for the HRESULT.
REQUIRE(winrt::hresult_error(E_FAIL, L"message").message() == L"Unspecified error");

winrt::check_hresult(RoSetErrorReportingFlags(RO_ERROR_REPORTING_USESETERRORINFO));

// The default behavior has been restored, so C++/WinRT can faithfully provide error
// information as usual.
REQUIRE(winrt::hresult_error(E_FAIL, L"message").message() == L"message");
}
1 change: 1 addition & 0 deletions test/test/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@
<ClCompile Include="single_threaded_observable_vector.cpp" />
<ClCompile Include="structs.cpp" />
<ClCompile Include="struct_delegate.cpp" />
<ClCompile Include="suppress_error_info.cpp" />
<ClCompile Include="tearoff.cpp" />
<ClCompile Include="thread_pool.cpp" />
<ClCompile Include="uniform_in_params.cpp" />
Expand Down

0 comments on commit 2bfcd75

Please sign in to comment.