From 51e95ea9464e3ee4bb02b7ba2339266af1c54f77 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Wed, 25 Mar 2020 12:20:40 -0700 Subject: [PATCH] Make ort errors appear in winml exceptions (#3316) Co-authored-by: Sheil Kumar --- winml/lib/Api.Ort/OnnxruntimeErrors.h | 9 +++++---- winml/lib/Common/inc/errors.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/winml/lib/Api.Ort/OnnxruntimeErrors.h b/winml/lib/Api.Ort/OnnxruntimeErrors.h index 4184613ac8..7d041870a3 100644 --- a/winml/lib/Api.Ort/OnnxruntimeErrors.h +++ b/winml/lib/Api.Ort/OnnxruntimeErrors.h @@ -46,8 +46,9 @@ inline HRESULT OrtErrorCodeToHRESULT(OrtErrorCode status) noexcept { auto error_message = ort_api->GetErrorMessage(_status); \ HRESULT hresult = OrtErrorCodeToHRESULT(error_code); \ telemetry_helper.LogRuntimeError(hresult, std::string(error_message), __FILE__, __FUNCTION__, __LINE__); \ - RETURN_HR_MSG(hresult, \ - error_message); \ + auto message = WinML::Strings::HStringFromUTF8(error_message); \ + RoOriginateError(hresult, reinterpret_cast(winrt::get_abi(message))); \ + return hresult; \ } \ } while (0) @@ -59,7 +60,7 @@ inline HRESULT OrtErrorCodeToHRESULT(OrtErrorCode status) noexcept { auto error_message = ort_api->GetErrorMessage(_status); \ HRESULT hresult = OrtErrorCodeToHRESULT(error_code); \ telemetry_helper.LogRuntimeError(hresult, std::string(error_message), __FILE__, __FUNCTION__, __LINE__); \ - winrt::hstring errorMessage(WinML::Strings::HStringFromUTF8(error_message)); \ - throw winrt::hresult_error(hresult, errorMessage); \ + auto message = WinML::Strings::HStringFromUTF8(error_message); \ + throw winrt::hresult_error(hresult, message); \ } \ } while (0) diff --git a/winml/lib/Common/inc/errors.h b/winml/lib/Common/inc/errors.h index 2875c7f7d0..067e3eaefd 100644 --- a/winml/lib/Common/inc/errors.h +++ b/winml/lib/Common/inc/errors.h @@ -44,7 +44,7 @@ { \ auto _result = hr; \ telemetry_helper.LogRuntimeError(_result, "", __FILE__, __FUNCTION__, __LINE__); \ - throw winrt::hresult_error(_result); \ + throw winrt::hresult_error(_result, winrt::hresult_error::from_abi); \ } #define WINML_THROW_IF_FAILED(hr) \ @@ -52,7 +52,7 @@ HRESULT _hr = hr; \ if (FAILED(_hr)) { \ telemetry_helper.LogRuntimeError(_hr, "", __FILE__, __FUNCTION__, __LINE__); \ - throw winrt::hresult_error(_hr); \ + throw winrt::hresult_error(_hr, winrt::hresult_error::from_abi); \ } \ } while (0)