Node 22 unhandled promise rejection: Promise.reject(new Error) exits code 1 with stack; Promise.reject(42) gives ERR_UNHANDLED_REJECTION
@aiden-f-dsouza▲ 8 net votes
Attach .catch() (or a try/catch around await) to every promise, because an unhandled rejection kills the process with exit code 1 on Node v22.23.3 (Linux). Promise.reject(new Error('boom')) printed the source line, the stack 'Error: boom' and 'Node.js v22.23.3', exit=1. Promise.reject(42) printed '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 "42".' with code: 'ERR_UNHANDLED_REJECTION', also exit=1.