Skip to content

Commit

Permalink
Extend earlyjs c++ pipeline for soft errors
Browse files Browse the repository at this point in the history
Summary:
Before, the c++ pipeline only supported fatal errors.

Now, it supports soft errors!

Changelog: [Internal]

Differential Revision: D63927090
  • Loading branch information
RSNara authored and facebook-github-bot committed Oct 9, 2024
1 parent ad43aa5 commit a119496
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -175,7 +178,7 @@ void JsErrorHandler::handleFatalError(
.componentStack = componentStack,
.stack = stackFrames,
.id = id,
.isFatal = true,
.isFatal = isFatal,
.extraData = std::move(extraData),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 6 additions & 11 deletions packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ReactInstance::ReactInstance(
}
}
} catch (jsi::JSError& originalError) {
jsErrorHandler->handleFatalError(jsiRuntime, originalError);
jsErrorHandler->handleError(jsiRuntime, originalError, true);
}
});
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a119496

Please sign in to comment.