Skip to content

Don't print an error and exit on uncaughtException if there are other uncaughtException listeners present. #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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