forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: change default --unhandled-rejections=throw
This is a semver-major change that resolves DEP0018. All users that have set an unhandledRejection hook or set a non-default value for the --unhandled-rejections flag will see no change in behavior after this change. Refs: https://nodejs.org/dist/latest/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections PR-URL: nodejs#33021 Fixes: nodejs#20392 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Mary Marchini <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
- Loading branch information
Showing
15 changed files
with
73 additions
and
97 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
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
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
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
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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
// Flags: --unhandled-rejections=warn-with-error-code | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
common.disableCrashOnUnhandledRejection(); | ||
|
||
Promise.reject(new Error('alas')); | ||
process.on('exit', assert.strictEqual.bind(null, 1)); |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// Flags: --trace-warnings | ||
// Flags: --trace-warnings --unhandled-rejections=warn | ||
'use strict'; | ||
const common = require('../common'); | ||
common.disableCrashOnUnhandledRejection(); | ||
require('../common'); | ||
const p = Promise.reject(new Error('This was rejected')); | ||
setImmediate(() => p.catch(() => {})); |
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
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,52 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const Countdown = require('../common/countdown'); | ||
const assert = require('assert'); | ||
|
||
// Verify that unhandled rejections always trigger uncaught exceptions instead | ||
// of triggering unhandled rejections. | ||
|
||
const err1 = new Error('One'); | ||
const err2 = new Error( | ||
'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(). The promise rejected with the' + | ||
' reason "null".' | ||
); | ||
err2.code = 'ERR_UNHANDLED_REJECTION'; | ||
Object.defineProperty(err2, 'name', { | ||
value: 'UnhandledPromiseRejection', | ||
writable: true, | ||
configurable: true | ||
}); | ||
|
||
const errors = [err1, err2]; | ||
const identical = [true, false]; | ||
|
||
const ref = new Promise(() => { | ||
throw err1; | ||
}); | ||
// Explicitly reject `null`. | ||
Promise.reject(null); | ||
|
||
process.on('warning', common.mustNotCall('warning')); | ||
// If we add an unhandledRejection handler, the exception won't be thrown | ||
// process.on('unhandledRejection', common.mustCall(2)); | ||
process.on('rejectionHandled', common.mustNotCall('rejectionHandled')); | ||
process.on('exit', assert.strictEqual.bind(null, 0)); | ||
|
||
const timer = setTimeout(() => console.log(ref), 1000); | ||
|
||
const counter = new Countdown(2, () => { | ||
clearTimeout(timer); | ||
}); | ||
|
||
process.on('uncaughtException', common.mustCall((err, origin) => { | ||
counter.dec(); | ||
assert.strictEqual(origin, 'unhandledRejection', err); | ||
const knownError = errors.shift(); | ||
assert.deepStrictEqual(err, knownError); | ||
// Check if the errors are reference equal. | ||
assert(identical.shift() ? err === knownError : err !== knownError); | ||
}, 2)); |
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
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
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
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
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
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
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