Skip to content

Commit

Permalink
update error strings (microsoft#5993)
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau authored Sep 30, 2021
1 parent c8c76f0 commit 9672592
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions dev/WebView2/WebView2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <uiautomationclient.h>
#include <WebView2Interop.h>

static constexpr wstring_view s_error_wv2_closed{ L"Cannot create CoreWebView2 for Closed WebView2 element."sv };
static constexpr wstring_view s_error_cwv2_not_present{ L"Failed because a valid CoreWebView2 is not present. Make sure one was created, for example by calling EnsureCoreWebView2Async() API."sv };
static constexpr wstring_view s_error_cwv2_not_present_closed{ L"Failed because a valid CoreWebView2 is not present. One existed, but has been closed."sv };

WebView2::WebView2()
{
if (auto user32module = GetModuleHandleW(L"user32.dll"))
Expand Down Expand Up @@ -168,7 +172,7 @@ void WebView2::OnPropertyChanged(winrt::DependencyPropertyChangedEventArgs const
}
else
{
throw winrt::hresult_error(RO_E_CLOSED, L"Cannot create CoreWebView2 (via Source) for Closed WebView2 element.");
throw winrt::hresult_error(RO_E_CLOSED, s_error_wv2_closed);
}
}
}
Expand Down Expand Up @@ -466,7 +470,7 @@ winrt::IAsyncAction WebView2::OnSourceChanged(winrt::Uri providedUri)
// Try to apply latest source (could have changed during the co_await's above)
if (m_isClosed)
{
throw winrt::hresult_error(RO_E_CLOSED, L"Cannot create CoreWebView2 (via Source) for Closed WebView2 element.");
throw winrt::hresult_error(RO_E_CLOSED, s_error_wv2_closed);
}
const auto updatedUri = this->Source();
if (!updatedUri.Equals(providedUri) && ShouldNavigate(updatedUri))
Expand Down Expand Up @@ -662,7 +666,7 @@ winrt::IAsyncAction WebView2::CreateCoreObjects()

if (m_isClosed)
{
throw winrt::hresult_error(RO_E_CLOSED, L"Cannot create CoreWebView2 (via Source) for Closed WebView2 element.");
throw winrt::hresult_error(RO_E_CLOSED, s_error_wv2_closed);
}
else
{
Expand Down Expand Up @@ -1537,7 +1541,7 @@ winrt::IAsyncOperation<winrt::hstring> WebView2::ExecuteScriptAsync(winrt::hstri
}
else
{
throw winrt::hresult_illegal_method_call(L"ExecuteScriptAsync() failed because a valid CoreWebView2 is not present.");
throw winrt::hresult_illegal_method_call(std::wstring(L"ExecuteScriptAsync(): ").append(s_error_cwv2_not_present));
}

co_return returnedValue;
Expand Down Expand Up @@ -1630,11 +1634,11 @@ void WebView2::Reload()
{
if (m_everHadCoreWebView)
{
throw winrt::hresult_illegal_method_call(L"Reload() failed because a valid CoreWebView2 is not present. (and never had a CoreWebView)");
throw winrt::hresult_illegal_method_call(std::wstring(L"Reload(): ").append(s_error_cwv2_not_present_closed));
}
else
{
throw winrt::hresult_illegal_method_call(L"Reload() failed because a valid CoreWebView2 is not present. (unloaded core webview)");
throw winrt::hresult_illegal_method_call(std::wstring(L"Reload(): ").append(s_error_cwv2_not_present));
}
}
}
Expand All @@ -1647,7 +1651,7 @@ void WebView2::NavigateToString(winrt::hstring htmlContent)
}
else
{
throw winrt::hresult_illegal_method_call(L"NavigateToString() failed because a valid CoreWebView2 is not present.");
throw winrt::hresult_illegal_method_call(std::wstring(L"NavigateToString(): ").append(s_error_cwv2_not_present));
}
}

Expand Down

0 comments on commit 9672592

Please sign in to comment.