Repository navigation
Commit bd6748d
Route napi_fatal_exception through ErrorUtils.reportFatalError (#432)
HostContext::fatalException previously stringified the error and called
abort() unconditionally, matching Hermes' null-host default but giving
node-addon-api's tsfn error path (which calls napi_fatal_exception whenever
an exception escapes a thread-safe-function callback) no chance of being
observed or handled — a single throwing tsfn callback hard-killed the app
with no LogBox and no JS-side handler getting a say.
napi_fatal_exception (unlike the noreturn napi_fatal_error) is a plain
napi_status-returning function, and the pinned Hermes commit's
hermes_napi_error.cpp explicitly supports the host hook returning normally,
so routing can be done synchronously against the passed env with plain
Node-API calls, keeping HermesNapiHost.cpp free of React Native/JSI
includes:
- Attempt global.ErrorUtils.reportFatalError(err) via napi_get_global +
napi_get_named_property (x2, type-checked at each step) +
napi_call_function.
- On success, return normally (napi_ok reaches the addon), matching Node's
process.emit('uncaughtException') returning to the caller when a handler
is installed.
- On any failure (ErrorUtils/reportFatalError absent or not the right
type, or the call itself throwing) fall back to the previous stringify +
log_error + abort() path, clearing any pending exception first so the
fallback's own Node-API calls aren't defeated by a stale exception.
- Guard reentrancy with a HostContext member flag: if the ErrorUtils
handler itself triggers another napi_fatal_exception, the nested call
skips straight to the fallback instead of recursing.
Adds a "minor" changeset for react-native-node-api: this is an observable
behavior change for addons/apps that relied on the previous immediate
abort.
Not compiled or exercised on-device in this environment (no Android/iOS
toolchain here) — see the PR description for what remains to be verified.
Closes #402
Claude-Session: https://claude.ai/code/session_01DaK9eAAF5G8wj6UT8VekAm
Co-authored-by: Claude <noreply@anthropic.com>1 parent ed0d4c5 commit bd6748d
3 files changed
Lines changed: 98 additions & 13 deletions
File tree
- .changeset
- packages/host/cpp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
152 | 209 | | |
153 | 210 | | |
154 | 211 | | |
| |||
232 | 289 | | |
233 | 290 | | |
234 | 291 | | |
235 | | - | |
| 292 | + | |
236 | 293 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
249 | 323 | | |
250 | 324 | | |
251 | 325 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
0 commit comments