diff --git a/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp b/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp index 95578b0dc356b7..0caaf125ee10b1 100644 --- a/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp +++ b/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp @@ -91,16 +91,19 @@ JsErrorHandler::JsErrorHandler(JsErrorHandler::OnJsError onJsError) JsErrorHandler::~JsErrorHandler() {} -void JsErrorHandler::handleFatalError( +void JsErrorHandler::handleError( jsi::Runtime& runtime, - jsi::JSError& error) { + jsi::JSError& error, + bool isFatal) { // TODO: Current error parsing works and is stable. Can investigate using // REGEX_HERMES to get additional Hermes data, though it requires JS setup. - _hasHandledFatalError = true; + if (isFatal) { + _hasHandledFatalError = true; + } if (_isRuntimeReady) { try { - handleJSError(runtime, error, true); + handleJSError(runtime, error, isFatal); return; } catch (jsi::JSError& e) { LOG(ERROR) @@ -175,7 +178,7 @@ void JsErrorHandler::handleFatalError( .componentStack = componentStack, .stack = stackFrames, .id = id, - .isFatal = true, + .isFatal = isFatal, .extraData = std::move(extraData), }; diff --git a/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.h b/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.h index 372a81f358c3c5..d46ba183f62adf 100644 --- a/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.h +++ b/packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.h @@ -43,7 +43,7 @@ class JsErrorHandler { explicit JsErrorHandler(OnJsError onJsError); ~JsErrorHandler(); - void handleFatalError(jsi::Runtime& runtime, jsi::JSError& error); + void handleError(jsi::Runtime& runtime, jsi::JSError& error, bool isFatal); bool hasHandledFatalError(); void setRuntimeReady(); bool isRuntimeReady(); diff --git a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp index 66155b271114c6..db90f4a60b1009 100644 --- a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp +++ b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp @@ -84,7 +84,7 @@ ReactInstance::ReactInstance( } } } catch (jsi::JSError& originalError) { - jsErrorHandler->handleFatalError(jsiRuntime, originalError); + jsErrorHandler->handleError(jsiRuntime, originalError, true); } }); } @@ -129,7 +129,7 @@ ReactInstance::ReactInstance( RuntimeSchedulerClock::now, [jsErrorHandler = jsErrorHandler_]( jsi::Runtime& runtime, jsi::JSError& error) { - jsErrorHandler->handleFatalError(runtime, error); + jsErrorHandler->handleError(runtime, error, true); }); runtimeScheduler_->setPerformanceEntryReporter( // FIXME: Move creation of PerformanceEntryReporter to here and guarantee @@ -422,16 +422,11 @@ void ReactInstance::initializeRuntime( return jsi::Value(false); } - if (isFatal) { - auto jsError = jsi::JSError( - runtime, - jsi::Value( - runtime, wrapInErrorIfNecessary(runtime, args[0]))); - jsErrorHandler->handleFatalError(runtime, jsError); - return jsi::Value(true); - } + auto jsError = jsi::JSError( + runtime, wrapInErrorIfNecessary(runtime, args[0])); + jsErrorHandler->handleError(runtime, jsError, isFatal); - return jsi::Value(false); + return jsi::Value(true); })); defineReadOnlyGlobal(