forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
promise: warn on unhandled rejections
Log unhandled promise rejections with a guid and emit a process warning. When rejection is eventually handled, emit a secondary warning. PR-URL: nodejs#8223 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
- Loading branch information
1 parent
862610f
commit 180867d
Showing
2 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
test/parallel/test-promises-warning-on-unhandled-rejection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Flags: --no-warnings | ||
'use strict'; | ||
|
||
// Test that warnings are emitted when a Promise experiences an uncaught | ||
// rejection, and then again if the rejection is handled later on. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
var b = 0; | ||
|
||
process.on('warning', common.mustCall((warning) => { | ||
switch (b++) { | ||
case 0: | ||
assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning'); | ||
assert(/Unhandled promise rejection/.test(warning.message)); | ||
break; | ||
case 1: | ||
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning'); | ||
assert(/Promise rejection was handled asynchronously/ | ||
.test(warning.message)); | ||
} | ||
}, 2)); | ||
|
||
const p = Promise.reject('This was rejected'); | ||
setImmediate(common.mustCall(() => p.catch(() => {}))); |