node async_error ai_generated true

UnhandledPromiseRejectionWarning: Error: something failed

ID: node/unhandled-promise-rejection

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

Promise rejected without .catch() or try/catch in async. Crashes process in Node 15+.

generic

Workarounds

  1. 92% success Add try/catch in async functions or .catch() with proper error handling
    try { await fn() } catch(e) { logger.error(e) }

    Sources: https://nodejs.org/api/process.html#event-unhandledrejection

  2. 85% success Use Promise.allSettled() for parallel promises that may individually fail
    const results = await Promise.allSettled([p1, p2, p3])

    Sources: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled

Dead Ends

Common approaches that don't work:

  1. Add process.on('unhandledRejection') global handler 55% fail

    Catches everything, makes individual errors hard to debug

  2. Add .catch(() => {}) to silence 85% fail

    Swallows all errors silently

Error Chain

Frequently confused with: