Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [
'',
Expand Down