Skip to content

Commit

Permalink
Fix Node.js Worker support by not shimming uncaughtException
Browse files Browse the repository at this point in the history
Node.js Worker threads don’t handle `uncaughtException` the same way
that the main thread does. The shim does not apply/make sense here,
but breaks error handling support in unexpected ways instead.

Fixes: evanw/node-source-map-support#268
Fixes: TypeStrong/ts-node#945
  • Loading branch information
addaleax committed Apr 19, 2020
1 parent db386c8 commit bdba50e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source-map-support.js
Expand Up @@ -561,6 +561,17 @@ exports.install = function(options) {
var installHandler = 'handleUncaughtExceptions' in options ?
options.handleUncaughtExceptions : true;

// Do not override 'uncaughtException' with our own handler in Node.js
// Worker threads. Workers pass the error to the main thread as an event,
// rather than printing something to stderr and exiting.
try {
// Don't let browserify try to resolve this require(), it's pointless
// and breaks the build process.
var worker_threads = require('worker_' + 'threads');
if (worker_threads.isMainThread === false)
installHandler = false;
} catch(e) {}

// Provide the option to not install the uncaught exception handler. This is
// to support other uncaught exception handlers (in test frameworks, for
// example). If this handler is not installed and there are no other uncaught
Expand Down

0 comments on commit bdba50e

Please sign in to comment.