From c2882e4f6f869f07f5681d860220216eb8336edb Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 16 Mar 2020 10:23:06 +0100 Subject: [PATCH] Give better stack traces for Unhandled Promise Rejection warnings --- 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 5be5ccd72bd02..6321cd7ba8db0 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); + }); }