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(), [ '',