Skip to content

Route Hermes fatal errors to logcat with setFatalHandler #491

Closed as not planned

Description

@kraenhansen

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' ISetFatalHandler interface, 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 in RuntimeNodeApi.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 🏡 plus Android 🤖 CI).
  • Same for a Hermes fatal error unrelated to Node-API, if one can be triggered practically.

Related: #490, #447, #428

Activity

  1. added
    enhancementNew feature or request
    Android 🤖Anything related to the Android platform (Gradle, NDK, Android SDK)
    Host 🏡Our `react-native-node-api-modules` package
    on Oct 31, 2026
  2. kraenhansen commented on Oct 31, 2026

    @kraenhansen
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Android 🤖Anything related to the Android platform (Gradle, NDK, Android SDK)Host 🏡Our `react-native-node-api-modules` packageenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions