You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 91c4516
Browse filesBrowse the repository at this point in the historyBrowse files
> Minimal ESM-only Node.js process-level handler for uncaught exceptions, unhandled rejections, and warnings.
@@ -81,11 +83,51 @@ Registers process-level exception handlers. Returns an object with a `removeHand
81
83
-`events`: Supported event names to register (default: all three)
82
84
-`once`: Use one-shot listeners when supported
83
85
-`signal`: AbortSignal that automatically removes handlers
84
-
-**Returns:**`{ removeHandlers: () => void, removed: boolean }`; call it to detach the selected handlers. `processObj` must provide `on` plus `off` or `removeListener`.
86
+
-**Returns:**`{ removeHandlers: () => void, removed: boolean }`; call it to detach the selected handlers. `removed` is runtime-mutated from `false` to `true` after successful cleanup and should be treated as read-only by consumers.
87
+
- Each event is removed once.
88
+
- If an event or abort-listener removal throws, successful removals are not retried; a later call retries only failed removals.
89
+
- A failed event cleanup leaves `removed` set to `false`; inspect the thrown error and retry `removeHandlers()` after correcting the target.
90
+
-`processObj` methods are called with `processObj` as their receiver. The target must provide callable `on` plus `off` or `removeListener`; `once` is optional and is used only when `once: true`. Synchronous callbacks from custom `once()` or `addEventListener()` implementations are supported; cleanup is reconciled after setup completes.
91
+
-`log` must provide callable `error`, `warn`, and `debug` methods; malformed loggers are rejected during registration.
92
+
93
+
Registration is idempotent per process-like object; repeated calls return the existing registration. Cleanup is safe to call repeatedly and removes the registration from the internal registry. The returned `removed` property becomes `true` after successful cleanup, including one-shot and AbortSignal cleanup. Existing listeners are preserved. For production use, remember that handling `uncaughtException` can leave the process in an unsafe state; log it and shut down gracefully when appropriate.
94
+
95
+
Idempotence uses first-registration-wins semantics: options supplied by a later
96
+
call are not applied to an existing registration. Call `removeHandlers()`
97
+
before registering again with different options.
98
+
This applies to later `events`, `log`, `once`, and `signal` options; they are
99
+
ignored until the existing registration is removed.
100
+
101
+
The `signal` option removes handlers when the signal aborts; retain the
102
+
registration or controller when explicit lifecycle control is needed:
Registration is idempotent per process-like object; repeated calls return the existing registration. Cleanup is safe to call repeatedly and removes the registration from the internal registry. Existing listeners are preserved. For production use, remember that handling `uncaughtException` can leave the process in an unsafe state; log it and shut down gracefully when appropriate.
111
+
For graceful shutdown, keep the registration and remove it from the shutdown
112
+
hook:
87
113
88
-
Logger failures and listener-registration/removal failures are propagated to the caller. If registration fails partway through, listeners already added by this package are rolled back.
Logger failures and listener-registration/removal failures are propagated to the caller. If registration fails partway through, listeners already added by this package are rolled back. Event-handler logger failures also propagate; custom loggers should handle their own transport failures so they do not obscure the original process event.
120
+
If rollback itself fails during setup, the original error remains the thrown error
121
+
and the cleanup failure is available as `error.rollbackError`; if one-shot handler
122
+
cleanup fails after a logger error, it is available as `error.cleanupError`.
123
+
These secondary properties are best-effort and are unavailable when the primary
124
+
thrown value is primitive or non-extensible.
125
+
When rollback fails, the registration remains in the internal registry so the
126
+
returned handle can be retried; later registration calls reuse that handle.
127
+
Because setup throws before returning its normal handle, the recovery handle is
128
+
also available as `error.registration` when the thrown error is extensible.
129
+
If abort-listener removal fails, the same retry rule applies: `removed` remains
130
+
`false` and a later `removeHandlers()` retries the failed signal cleanup.
89
131
90
132
## Configuration
91
133
@@ -100,31 +142,16 @@ provide `error(message, metadata)`, `warn(message, metadata)`, and
`removeHandlers()` returns `void` when cleanup succeeds and throws if the process-like object rejects a removal; call it again to retry failed removals.
151
+
125
152
## Errors / Troubleshooting
126
153
127
-
The package only registers handlers; it does not terminate or restart the process. After an uncaught exception, log the failure and shut down gracefully when appropriate. Use a process-like object and custom logger in tests.
154
+
The package only registers handlers; it does not terminate or restart the process. After an uncaught exception, log the failure and shut down gracefully when appropriate. Because logger failures propagate from event handlers, production loggers should be reliable and applications should have a shutdown path that does not depend on logging succeeding. Use a process-like object and custom logger in tests.
128
155
129
156
## Development
130
157
@@ -138,7 +165,11 @@ npm run pack
138
165
139
166
## Security
140
167
141
-
Do not expose sensitive exception or rejection data through custom loggers. Review logger configuration and redact secrets before logging process errors.
0 commit comments