From ee89d3766a1645e6455d9b8c5297f96ab691bc1e Mon Sep 17 00:00:00 2001 From: Chris Breneman Date: Mon, 16 Mar 2015 15:58:47 -0400 Subject: [PATCH] Don't print an error and exit on uncaughtException if there are other uncaughtException listeners present. --- source-map-support.js | 4 +++- test.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source-map-support.js b/source-map-support.js index 07048d8..63163ec 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -335,7 +335,9 @@ function getErrorSource(error) { // Mimic node's stack trace printing when an exception escapes the process function handleUncaughtExceptions(error) { - if (!error || !error.stack) { + if (process.listeners('uncaughtException').length > 1) { + return; + } else if (!error || !error.stack) { console.log('Uncaught exception:', error); } else { var source = getErrorSource(error); diff --git a/test.js b/test.js index f2bf344..2fd51bf 100644 --- a/test.js +++ b/test.js @@ -296,6 +296,17 @@ it('handleUncaughtExceptions is false', function(done) { ]); }); +it('handleUncaughtExceptions is true with existing listener', function(done) { + compareStdout(done, createSingleLineSourceMap(), [ + 'process.on("uncaughtException", function() { console.log("exception handler"); });', + 'function foo() { throw new Error("this is the error"); }', + 'require("./source-map-support").install({ handleUncaughtExceptions: false });', + 'process.nextTick(foo);' + ], [ + 'exception handler' + ]); +}); + it('default options with empty source map', function(done) { compareStdout(done, createEmptySourceMap(), [ '',