| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 72b4de5 commit 4c2b79d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,11 @@ let lastPromiseId = 1; | |||
| 8 | 8 | ||
| 9 | 9 | exports.setup = setupPromises; | |
| 10 | 10 | ||
| 11 | + function getAsynchronousRejectionWarningObject(uid) { | ||
| 12 | + return new Error('Promise rejection was handled ' + | ||
| 13 | + `asynchronously (rejection id: ${uid})`); | ||
| 14 | + } | ||
| 15 | + | ||
| 11 | 16 | function setupPromises(scheduleMicrotasks) { | |
| 12 | 17 | process._setupPromises(function(event, promise, reason) { | |
| 13 | 18 | if (event === promiseRejectEvent.unhandled) | |
@@ -31,10 +36,15 @@ function setupPromises(scheduleMicrotasks) { | |||
| 31 | 36 | const uid = promiseToGuidProperty.get(promise); | |
| 32 | 37 | promiseToGuidProperty.delete(promise); | |
| 33 | 38 | if (hasBeenNotified === true) { | |
| 39 | + let warning = null; | ||
| 40 | + if (!process.listenerCount('rejectionHandled')) { | ||
| 41 | + // Generate the warning object early to get a good stack trace. | ||
| 42 | + warning = getAsynchronousRejectionWarningObject(uid); | ||
| 43 | + } | ||
| 34 | 44 | process.nextTick(function() { | |
| 35 | 45 | if (!process.emit('rejectionHandled', promise)) { | |
| 36 | - const warning = new Error('Promise rejection was handled ' + | ||
| 37 | - `asynchronously (rejection id: ${uid})`); | ||
| 46 | + if (warning === null) | ||
| 47 | + warning = getAsynchronousRejectionWarningObject(uid); | ||
| 38 | 48 | warning.name = 'PromiseRejectionHandledWarning'; | |
| 39 | 49 | warning.id = uid; | |
| 40 | 50 | process.emitWarning(warning); | |
@@ -58,6 +68,9 @@ function setupPromises(scheduleMicrotasks) { | |||
| 58 | 68 | `(rejection id: ${uid}): ${reason}`); | |
| 59 | 69 | warning.name = 'UnhandledPromiseRejectionWarning'; | |
| 60 | 70 | warning.id = uid; | |
| 71 | + if (reason instanceof Error) { | ||
| 72 | + warning.stack = reason.stack; | ||
| 73 | + } | ||
| 61 | 74 | process.emitWarning(warning); | |
| 62 | 75 | } else { | |
| 63 | 76 | hadListeners = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + // Flags: --trace-warnings | ||
| 2 | + 'use strict'; | ||
| 3 | + require('../common'); | ||
| 4 | + const p = Promise.reject(new Error('This was rejected')); | ||
| 5 | + setImmediate(() => p.catch(() => {})); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + (node:*) Error: This was rejected | ||
| 2 | + at * (*test*message*unhandled_promise_trace_warnings.js:*) | ||
| 3 | + at * | ||
| 4 | + at * | ||
| 5 | + at * | ||
| 6 | + at * | ||
| 7 | + at * | ||
| 8 | + at * | ||
| 9 | + at * | ||
| 10 | + at * | ||
| 11 | + at * | ||
| 12 | + (node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1) | ||
| 13 | + at getAsynchronousRejectionWarningObject (internal/process/promises.js:*) | ||
| 14 | + at rejectionHandled (internal/process/promises.js:*) | ||
| 15 | + at * | ||
| 16 | + at Promise.then (native) | ||
| 17 | + at Promise.catch (native) | ||
| 18 | + at Immediate.setImmediate (*test*message*unhandled_promise_trace_warnings.js:*) | ||
| 19 | + at * | ||
| 20 | + at * | ||
| 21 | + at * | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments