From 2f0977d8e4611dc77fa525317c231f7d53ac1db7 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Thu, 5 Dec 2024 09:42:44 -0800 Subject: [PATCH] Also report non-fatal non-warning errors (#48104) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48104 Just porting over the logic after D28815228. Changelog: [Internal] Reviewed By: mlord93 Differential Revision: D66563226 fbshipit-source-id: 41e21812dd0b2104fa66b970212f51bbb77d910b --- .../jserrorhandler/JsErrorHandler.cpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp b/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp index a8e3f4069af..20c6b48c424 100644 --- a/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp +++ b/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp @@ -29,9 +29,12 @@ bool isLooselyNull(const jsi::Value& value) { return value.isNull() || value.isUndefined(); } -bool isEmptyString(jsi::Runtime& runtime, const jsi::Value& value) { +bool isEqualTo( + jsi::Runtime& runtime, + const jsi::Value& value, + const std::string& str) { return jsi::Value::strictEquals( - runtime, value, jsi::String::createFromUtf8(runtime, "")); + runtime, value, jsi::String::createFromUtf8(runtime, str)); } std::string stringifyToCpp(jsi::Runtime& runtime, const jsi::Value& value) { @@ -265,7 +268,7 @@ void JsErrorHandler::handleErrorWithCppPipeline( } auto nameValue = errorObj.getProperty(runtime, "name"); - auto name = (isLooselyNull(nameValue) || isEmptyString(runtime, nameValue)) + auto name = (isLooselyNull(nameValue) || isEqualTo(runtime, nameValue, "")) ? std::nullopt : std::optional(stringifyToCpp(runtime, nameValue)); @@ -383,14 +386,19 @@ void JsErrorHandler::handleErrorWithCppPipeline( return; } - if (isFatal) { - if (_hasHandledFatalError) { - return; - } - _hasHandledFatalError = true; - } + auto errorType = errorObj.getProperty(runtime, "type"); + auto isWarn = isEqualTo(runtime, errorType, "warn"); - _onJsError(runtime, parsedError); + if (isFatal || !isWarn) { + if (isFatal) { + if (_hasHandledFatalError) { + return; + } + _hasHandledFatalError = true; + } + + _onJsError(runtime, parsedError); + } } void JsErrorHandler::registerErrorListener(