Closed
Description
Node v9.3.0 on Linux (I would expect other versions since the introduction of the deprecation warning stuff - and other platforms - to behave the same way)
Current behavior
It doesn't matter whether you use process.throwDeprecation = true
or node --throw-deprecation
here, the behavior is the same.
async function x() {
throw new Error( 'aaaa' );
}
process.throwDeprecation = true;
x().then( r => console.log( r ) );
$ node test1.js
internal/process/warning.js:143
throw warning;
^
DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitWarning (internal/process/promises.js:92:15)
at emitPendingUnhandledRejections (internal/process/promises.js:109:11)
at runMicrotasksCallback (internal/process/next_tick.js:118:9)
at process._tickCallback (internal/process/next_tick.js:150:11)
at Function.Module.runMain (module.js:703:11)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:618:3
Expected behavior
Note concise output that preserves the original error stack without adding irrelevant stuff.
async function x() {
throw new Error( 'aaaa' );
}
process.on( 'unhandledRejection', err => {
console.error( 'Unhandled promise rejection:', err );
process.exit( 1 );
} );
x().then( r => console.log( r ) );
$ node test2.js
Unhandled promise rejection: Error: aaaa
at x (../test2.js:2:8)
at Object.<anonymous> (.../test2.js:10:1)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:618:3