From 8c66f481255113801bf3c9422dec8016421f7d54 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Fri, 15 Oct 2021 21:04:29 -0700 Subject: [PATCH 1/3] Catch and report errors in linking module --- .../Modules/LinkingManagerModule.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp index 722eefd4b5b..80e075534ab 100644 --- a/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp @@ -103,14 +103,24 @@ auto LinkingManagerModule::getMethods() -> std::vector { Method( "openURL", [](folly::dynamic args, Callback successCallback, Callback errorCallback) { - winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(facebook::xplat::jsArgAsString(args, 0))); - openURLAsync(uri, successCallback, errorCallback); + auto inputUrl = facebook::xplat::jsArgAsString(args, 0); + try { + winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(inputUrl)); + openURLAsync(uri, successCallback, errorCallback); + } catch (winrt::hresult_error& e) { + errorCallback({folly::dynamic::object("code", e.code().value)( + "message", "Unable to open URL: " + inputUrl)}); + } }), Method( "canOpenURL", [](folly::dynamic args, Callback successCallback, Callback errorCallback) { - winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(facebook::xplat::jsArgAsString(args, 0))); - canOpenURLAsync(uri, successCallback, errorCallback); + try { + winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(facebook::xplat::jsArgAsString(args, 0))); + canOpenURLAsync(uri, successCallback, errorCallback); + } catch (winrt::hresult_error& e) { + successCallback({false}); + } }), Method( "getInitialURL", From 62beb10555f0897b1ee713f3499527dec998856f Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Fri, 15 Oct 2021 21:06:24 -0700 Subject: [PATCH 2/3] format --- .../Modules/LinkingManagerModule.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp b/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp index 80e075534ab..fec8527f3a7 100644 --- a/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp @@ -107,9 +107,9 @@ auto LinkingManagerModule::getMethods() -> std::vector { try { winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(inputUrl)); openURLAsync(uri, successCallback, errorCallback); - } catch (winrt::hresult_error& e) { - errorCallback({folly::dynamic::object("code", e.code().value)( - "message", "Unable to open URL: " + inputUrl)}); + } catch (winrt::hresult_error &e) { + errorCallback( + {folly::dynamic::object("code", e.code().value)("message", "Unable to open URL: " + inputUrl)}); } }), Method( @@ -118,7 +118,7 @@ auto LinkingManagerModule::getMethods() -> std::vector { try { winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(facebook::xplat::jsArgAsString(args, 0))); canOpenURLAsync(uri, successCallback, errorCallback); - } catch (winrt::hresult_error& e) { + } catch (winrt::hresult_error &e) { successCallback({false}); } }), From 89c1d50d6e0376c5a30b3d2e1fed46f8fd98a203 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Fri, 15 Oct 2021 21:06:37 -0700 Subject: [PATCH 3/3] Change files --- ...ative-windows-4ab9e54e-d49e-49da-a4a1-f2a2d8218f94.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-4ab9e54e-d49e-49da-a4a1-f2a2d8218f94.json diff --git a/change/react-native-windows-4ab9e54e-d49e-49da-a4a1-f2a2d8218f94.json b/change/react-native-windows-4ab9e54e-d49e-49da-a4a1-f2a2d8218f94.json new file mode 100644 index 00000000000..f2523ff6d3d --- /dev/null +++ b/change/react-native-windows-4ab9e54e-d49e-49da-a4a1-f2a2d8218f94.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Catch and report errors in linking module", + "packageName": "react-native-windows", + "email": "asklar@microsoft.com", + "dependentChangeType": "patch" +}