问题
In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
My pipeline passed when it should have failed and deployed a version that is crashing on launch. If Node.js would have exited with a non-zero exit code, the pipeline would have failed and the bad version wouldn't have been deployed.
Is there a way to make Node.js exit with a non-zero exit code when it encounters an unhandled promise rejection, that doesn't require me to wait for the future?
回答1:
Yes, you can, using the unhandledRejection event on the process object:
process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled Rejection at:', p, 'reason:', reason)
process.exit(1)
});
回答2:
For node
12 and later:
node --unhandled-rejections=strict
来源:https://stackoverflow.com/questions/51632965/can-i-get-the-future-unhandled-promise-rejection-behaviour-now