Skip to content

Commit 2bfcd75

Browse files
authored
Fail gracefully when error reporting is suppressed (#1386)
1 parent 25a14f8 commit 2bfcd75

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

strings/base_error.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ WINRT_EXPORT namespace winrt
313313
}
314314

315315
com_ptr<impl::IErrorInfo> info;
316-
WINRT_VERIFY_(0, WINRT_IMPL_GetErrorInfo(0, info.put_void()));
317-
WINRT_VERIFY(info.try_as(m_info));
316+
WINRT_IMPL_GetErrorInfo(0, info.put_void());
317+
info.try_as(m_info);
318318
}
319319

320320
static hresult verify_error(hresult const code) noexcept

test/test/suppress_error_info.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "pch.h"
2+
#include <roerrorapi.h>
3+
4+
TEST_CASE("suppress_error_info")
5+
{
6+
winrt::check_hresult(RoSetErrorReportingFlags(RO_ERROR_REPORTING_SUPPRESSSETERRORINFO));
7+
8+
// Since the error information is suppressed, the best we can hope for is that C++/WinRT
9+
// will provide a generic message for the HRESULT.
10+
REQUIRE(winrt::hresult_error(E_FAIL, L"message").message() == L"Unspecified error");
11+
12+
winrt::check_hresult(RoSetErrorReportingFlags(RO_ERROR_REPORTING_USESETERRORINFO));
13+
14+
// The default behavior has been restored, so C++/WinRT can faithfully provide error
15+
// information as usual.
16+
REQUIRE(winrt::hresult_error(E_FAIL, L"message").message() == L"message");
17+
}

test/test/test.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@
418418
<ClCompile Include="single_threaded_observable_vector.cpp" />
419419
<ClCompile Include="structs.cpp" />
420420
<ClCompile Include="struct_delegate.cpp" />
421+
<ClCompile Include="suppress_error_info.cpp" />
421422
<ClCompile Include="tearoff.cpp" />
422423
<ClCompile Include="thread_pool.cpp" />
423424
<ClCompile Include="uniform_in_params.cpp" />

0 commit comments

Comments
 (0)