Skip to content

Commit

Permalink
lib: ensure every unhandled promise reason is wrapped in an error
Browse files Browse the repository at this point in the history
This change adds more debugging context to any unhandled promise.
If the unhandled promise does not have a reason which is an error,
it is very difficult to determine where the error came from.  This
ensures every reason has an appropriate stack trace before the
"next_tick" when the stack is lost.

Refs: nodejs#16768
  • Loading branch information
jd-carroll committed Jun 16, 2018
1 parent 1da8855 commit b2a100a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/process/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function setupPromises(_setupPromises) {
}

function unhandledRejection(promise, reason) {
if (process.traceProcessWarnings && !(reason instanceof Error)) {
reason = new Error(safeToString(reason));
}
maybeUnhandledPromises.set(promise, {
reason,
uid: ++lastPromiseId,
Expand Down

0 comments on commit b2a100a

Please sign in to comment.