Repository navigation
Route Hermes fatal errors to logcat with setFatalHandler #491
Description
Hermes fatal errors should reach logcat on Android without depending on weak-node-api, by having the host install a handler with Hermes' public setFatalHandler.
Problem
The host currently gets napi_fatal_error messages into logcat by shadowing Hermes' implementation (packages/host/cpp/RuntimeNodeApi.hpp). That only works for addons that go through the weak-node-api function table. An addon linked directly against Hermes (#490) calls Hermes' own napi_fatal_error.
Hermes' path is napi_fatal_error → hermes_fatal → llvh::report_fatal_error → hermesFatalErrorHandler (API/hermes/hermes.cpp). That handler writes to stderr, then calls the function set through setFatalHandler, if any. On Android stderr doesn't reach logcat.
React Native 0.88.1 does install a handler that logs through __android_log_assert, but only in HermesExecutorHolder (ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp). No fatal handler appears in JHermesInstance.cpp or HermesInstance.cpp, the new-architecture files, and the host only supports the new architecture. So, from reading the code, the message probably goes to stderr only. This hasn't been confirmed on a device.
The shadowing also misses Hermes' other fatal errors, which never pass through Node-API.
Proposal
- Install a fatal handler from the host once per process, through Hermes'
ISetFatalHandlerinterface, as React Native does. It should log through the host logger and terminate the process. - Once that covers
napi_fatal_error, remove the shadowing declaration and implementation inRuntimeNodeApi.hpp/.cpp, and the comment warning against doing so.
Questions to settle
- Does the handler overwrite one set by the app or React Native? Check it's safe if something else installs one, before or after.
- Where should it be installed so it's in place before any addon loads, on both Android and Apple?
Verification
- A fatal error from an addon shows up in logcat on a device or emulator (
Host 🏡plusAndroid 🤖CI). - Same for a Hermes fatal error unrelated to Node-API, if one can be triggered practically.
Activity
kraenhansen commentedon Oct 31, 2026
Closing in favour of react/react-native#59728. Hermes already handles fatal errors, and the handler is a single process-wide slot with no getter, so the host can't safely own it. React Native should install it instead, as proposed in react/react-native#59729. Once that lands, #492 can delete the host's
napi_fatal_error.