From 029d5e50b78c0b42056da606b0846247ec6a3f9c Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 17 Mar 2020 12:54:47 +0100 Subject: [PATCH] Give better stack traces for Unhandled Promise Rejection warnings (#60235) (#60352) --- src/setup_node_env/exit_on_warning.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/setup_node_env/exit_on_warning.js b/src/setup_node_env/exit_on_warning.js index 5be5ccd72bd024..6321cd7ba8db0f 100644 --- a/src/setup_node_env/exit_on_warning.js +++ b/src/setup_node_env/exit_on_warning.js @@ -35,4 +35,16 @@ if (process.noProcessWarnings !== true) { process.exit(1); }); + + // While the above warning listener would also be called on + // unhandledRejection warnings, we can give a better error message if we + // handle them separately: + process.on('unhandledRejection', function(reason) { + console.error('Unhandled Promise rejection detected:'); + console.error(); + console.error(reason); + console.error(); + console.error('Terminating process...'); + process.exit(1); + }); }