Skip to content

Commit

Permalink
process: unhandledRejection support more errors
Browse files Browse the repository at this point in the history
Support cross realm errors where `instanceof` errors in our
unhandledRejection warning to print better error with stack traces.
  • Loading branch information
benjamingr committed Jan 24, 2022
1 parent ce41395 commit c5093df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/internal/process/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
ArrayPrototypeShift,
Error,
ObjectDefineProperty,
ObjectHasOwn,
SafeWeakMap,
} = primordials;

Expand Down Expand Up @@ -179,14 +180,21 @@ function emitUnhandledRejectionWarning(uid, reason) {
`(rejection id: ${uid})`
);
try {
if (reason instanceof Error) {
if (ObjectHasOwn(reason, 'stack')) {
warning.stack = reason.stack;
process.emitWarning(reason.stack, unhandledRejectionErrName);
} else {
process.emitWarning(
noSideEffectsToString(reason), unhandledRejectionErrName);
}
} catch {}
} catch {
try {
process.emitWarning(
noSideEffectsToString(reason), unhandledRejectionErrName);
} catch {
// Ignore.
}
}

process.emitWarning(warning);
}
Expand Down

0 comments on commit c5093df

Please sign in to comment.