Skip to content

Commit 339e09f

Browse files
kraenhansenclaude
andauthored
Report Hermes fatal errors on the New Architecture (#59729)
* Report Hermes fatal errors on the New Architecture Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Install the Hermes fatal handler from HermesInstance::createJSRuntime Moves the handler from the Android-only JHermesInstance to the cross-platform HermesInstance, and logs through react_native_log_fatal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 46d183b commit 339e09f

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎packages/react-native/ReactCommon/react/runtime/React-RuntimeHermes.podspec‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Pod::Spec.new do |s|
3737
s.dependency "React-cxxstableapi"
3838
s.dependency "React-jsitracing"
3939
s.dependency "React-jsi"
40+
s.dependency "React-logger"
4041
s.dependency "React-utils"
4142
s.dependency "React-RuntimeCore"
4243
s.dependency "React-featureflags"

‎packages/react-native/ReactCommon/react/runtime/hermes/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ target_link_libraries(bridgelesshermes
2525
jsi
2626
jsitooling
2727
jsinspector
28+
logger
2829
react_cxxstableapi
2930
${reactnative}
3031
)

‎packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@
1010
#include <hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.h>
1111
#include <jsi/jsilib.h>
1212
#include <jsinspector-modern/InspectorFlags.h>
13+
#include <logger/react_native_log.h>
1314
#include <react/featureflags/ReactNativeFeatureFlags.h>
1415

16+
#include <mutex>
17+
1518
using namespace facebook::hermes;
1619
using namespace facebook::jsi;
1720

1821
namespace facebook::react {
1922

23+
static void hermesFatalHandler(const std::string& reason) {
24+
react_native_log_fatal(reason.c_str());
25+
}
26+
27+
static constinit std::once_flag fatalHandlerFlag;
28+
2029
class HermesJSRuntime : public JSRuntime {
2130
public:
2231
HermesJSRuntime(
@@ -53,6 +62,14 @@ std::unique_ptr<JSRuntime> HermesInstance::createJSRuntime(
5362
bool allocInOldGenBeforeTTI) noexcept {
5463
assert(msgQueueThread != nullptr);
5564

65+
std::call_once(fatalHandlerFlag, []() {
66+
auto* fatalHandlerInterface =
67+
jsi::castInterface<ISetFatalHandler>(makeHermesRootAPI());
68+
if (fatalHandlerInterface) {
69+
fatalHandlerInterface->setFatalHandler(hermesFatalHandler);
70+
}
71+
});
72+
5673
auto gcConfig = ::hermes::vm::GCConfig::Builder()
5774
// Default to 3GB
5875
.withMaxHeapSize(3072 << 20)

0 commit comments

Comments
 (0)