Skip to content

Commit

Permalink
Improved unhandled rejection message
Browse files Browse the repository at this point in the history
  • Loading branch information
MadaraUchiha committed Nov 20, 2017
1 parent 5c7b1ec commit a29fe91
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/internal/process/promises.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { safeToString } = process.binding('util');

const promiseRejectEvent = process._promiseRejectEvent;
const hasBeenNotifiedProperty = new WeakMap();
const promiseToGuidProperty = new WeakMap();
Expand Down Expand Up @@ -60,11 +58,23 @@ function setupPromises(scheduleMicrotasks) {
}

function emitWarning(uid, reason) {
try {
if (reason instanceof Error) {
process.emitWarning(reason.stack, 'UnhandledPromiseRejectionWarning');
} else {
process.emitWarning(reason, 'UnhandledPromiseRejectionWarning');
}
} catch (e) {
// ignored
}

const warning = new Error(
`Unhandled promise rejection (rejection id: ${uid}): ` +
safeToString(reason));
'Unhandled promise rejection. 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(). ' +
`(rejection id: ${uid})`
);
warning.name = 'UnhandledPromiseRejectionWarning';
warning.id = uid;
try {
if (reason instanceof Error) {
warning.stack = reason.stack;
Expand Down

0 comments on commit a29fe91

Please sign in to comment.