Repository navigation
cppwinrt.h: Improve conversion of error information - #498
Arthur Araujo (arthuraraujo-msft) wants to merge 3 commits into
Conversation
d31be81 to
0c81b43
Compare
|
I noticed that a few tests in ResultTests.cpp are failing because cppwinrt.h is included in the same compilation unit and affects those tests rather than them testing the normal environment. ResultTests seems to be inserted into all test executables. Should it have custom checks depending on where it's inserted? |
|
Correct me if I'm wrong, but you seem to effectively be using C++/WinRT as a way to call The new test failures seem very suspicious, though I can't quite comment on their cause without digging into it. |
|
Duncan Horn (@dunhor) I had no idea that existed! I just tested it out and it does lead to the exceptions having the proper messages. |
I don't see anything mentioning it in the error handling docs, which is where I'd expect to find it if something existed. I can add a pointer somewhere there later if nobody beats me to it. Now, there's a question that I think this PR raises as to whether or not cppwinrt.h should include result_originate.h by default as I think it's safe to say that if you're using C++/WinRT, you're using WinRT and probably want error origination. Idk if that might have any adverse side effects, though. E.g. idk if that would lead to the same sorts of issues as you're seeing with the test failures with this PR. David Machaj (@dmachaj) might have some insight here as I believe he's more familiar with the error origination logic than I am |
|
Duncan Horn (@dunhor) Thanks! That's a good point. I agree it could be interesting to include it by default. |
|
If it isn't mentioned in the docs then that is definitely a gap that would benefit from being filled. I think the result_originate functionality is super useful and that any binaries using COM extensively should include it. "Now, there's a question that I think this PR raises as to whether or not cppwinrt.h should include result_originate.h by default as I think it's safe to say that if you're using C++/WinRT, you're using WinRT and probably want error origination." I don't think cppwinrt headers have any dependency on WIL so that would be the explanation for why this doesn't already happen and would be tricky to add. The cppwinrt error origination already calls I think that if we want to improve the default situation then we should consider including <wil/result_originate.h> from some of the other WIL headers such as <wil/cppwinrt.h> or <wil/com.h>. |
Yes, when I said "there's a question that I think this PR raises as to whether or not cppwinrt.h should include result_originate.h by default" I was talking about wil/ cppwinrt.h |
|
Thanks folks. I'll close this PR since there is an existing flow to produce the same results! |
Closes #495
When using WIL with C++/WinRT with the
cppwinrt.hheader, thewinrt_to_hresult_handlerglobal handler is hooked from WIL directly into the C++/WinRT codebase.The handler allows WIL exceptions to be understood by C++/WinRT and their HRESULTs extracted, but messages are lost in the way when going over the API boundaries because only the HRESULT is converted in
winrt::to_hresult().C++/WinRT makes use of Get and SetErrorInfo() to recover the messages when re-creating the exceptions on the caller side. The set is done inside
winrt::hresult_error::to_abi()inwinrt::to_hresult()on the server side, but only whenwinrt_to_hresult_handleris not hooked. The retrieval happens when re-creating thewinrt::hresult_erroron the caller.If WIL were to call the
to_abi()method in the WIL hook forwinrt_to_hresult_handler, it would properly trigger the storage of the message and later on it could be retrieved when C++/WinRT creates a newwinrt::hresult_erroron the caller side.That's what this PR is doing.
I also added a test to cover the message being passed.