Error message
ERR_UNHANDLED_REJECTION in Node.js
A promise was rejected and nothing handled the rejection. Since Node.js 15, the default is to treat it as an uncaught exception: the process exits with code 1. The ERR_UNHANDLED_REJECTION code only appears when the rejection reason isn’t an Error. Installing the Sentry SDK changes the outcome: the process keeps running.
Examples run on 19 November 2026 with Node.js 24.21.0 and @sentry/node 9.47.2, 10.78.0 and 11.12.0. Errilo is in private beta.
What the message says
A promise rejected with something that isn’t an Error, here a string:
Promise.reject('timeout');Node.js wraps the reason in an error of its own and exits with code 1:
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "timeout".
at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
at processPromiseRejections (node:internal/process/promises:475:17)
at process.processTicksAndRejections (node:internal/process/task_queues:106:37) {
code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v24.21.0When the reason is an Error, Node.js throws that error as it is: you see your message and your stack trace, with no ERR_UNHANDLED_REJECTION anywhere, and the process still exits with code 1.
async function loadUser() {
throw new Error('user not found');
}
loadUser();In both cases, a process.on('uncaughtException') listener receives the error with origin set to 'unhandledRejection'.
Node.js behavior and the --unhandled-rejections flag
The default mode has been throw since Node.js 15: the rejection is raised as an uncaught exception, unless an unhandledRejection listener is registered. That last point is the one that matters in production. The other modes, checked with Node.js 24.21.0:
| Mode | Without a listener | With an unhandledRejection listener |
|---|---|---|
throw (default) | Uncaught exception, exit code 1 | The listener is called, the process keeps running |
strict | Uncaught exception, exit code 1 | Uncaught exception, exit code 1: the listener doesn’t prevent it |
warn | UnhandledPromiseRejectionWarning, the process keeps running, exit code 0 | — |
warn-with-error-code | Same warning, the process keeps running, then exits with code 1 | — |
Fixes
- Handle the rejection where the promise is created:
awaitinside atry, or.catch(). A promise launched withoutawait(fire and forget) needs its own.catch(). - Reject with
Errorobjects, never strings: a string has no stack trace, and the error tracker can’t tell two of them apart (see below). - Keep a last-resort listener that logs and exits, so a supervisor (systemd, Kubernetes, PM2) restarts a process whose state is no longer known.
async function loadUser(id) {
throw new Error(`user ${id} not found`);
}
// 1. Handle the rejection where the promise is created.
loadUser(42).catch((error) => {
console.error('could not load user:', error.message);
});
// 2. Last resort: log, then stop the process so the supervisor restarts it.
process.on('unhandledRejection', (reason) => {
console.error('unhandled rejection:', reason);
process.exit(1);
});What @sentry/node captures
The onUnhandledRejectionIntegration integration is enabled by default. It registers an unhandledRejection listener, and that changes Node.js’s behavior: in throw mode, a listener means no more crash. Its default mode is warn. What we observed with 9.47.2, 10.78.0 and 11.12.0:
- The rejection is sent as an event at level
error, marked unhandled (handled: false). - The SDK prints
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:, then the stack trace, on the error output. - The process keeps running, and exits with code 0 when it is done. Without the SDK, the same code exited with code 1.
- A string reason becomes an
Errorevent whose value is the string, and whose stack trace is generated by the SDK: it points into the SDK, not into your code. - In 10.78.0 and 11.12.0, a rejection whose error is named
AbortErroris ignored by default: no event, nothing printed, the process keeps running. The SDK’s list of default ignores also namesAI_NoOutputGeneratedError. In 9.47.2, anAbortErrorwas captured like any other.
To keep Node.js’s crash while reporting the error, switch the integration to strict. In our test, the event was sent at level fatal before the process exited with code 1:
import * as Sentry from '@sentry/node';
Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [Sentry.onUnhandledRejectionIntegration({ mode: 'strict' })],
});See the Node.js guide for the rest of the setup.
How Errilo shows it
The issue is titled with the error type and message (Error: user not found), with an Unhandled badge on the stack trace and the level, Fatal in strict mode. The issue’s location is the top frame of your code (loadUser).
Errilo groups on the exception type and the stack trace frames, not on the message. Rejections with strings all have the same type (Error) and the same stack trace, generated inside the SDK: in our test, Promise.reject('timeout') and Promise.reject('ECONNRESET') landed in the same issue, whose location points into @sentry/node. Two Error objects thrown from different functions gave two issues. One more reason to reject with Error.