Skip to content

Stack trace gets lost in Node.js 12.6.0 when rethrowing from uncaught exception handler  #28550

@basti1302

Description

@basti1302
  • Version: v12.6.0
  • Platform: Darwin Bastians-MBP 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

Up to version 12.5.0, when rethrowing the error from an uncaughtException handler, the original stack trace would be preserved. In version 12.6.0, this is no longer the case. Instead, a stack trace with only one line is printed, showing the callsite where the error has been rethrown.

rethrow.js:

'use strict';

process.on('uncaughtException', err => {
  throw err;
});

function throwUncaughtError() {
  throw new Error('Boom');
}

throwUncaughtError();

Running the above in 12.5.0 and 12.6.0 shows the difference:

> nvm use 12.5.0 && node rethrow

Now using node v12.5.0 (npm v6.9.0)
/Users/bastian/instana/code/nodejs/packages/collector/test/uncaught/apps/rethrow.js:4
  throw err;
  ^

Error: Boom
    at throwUncaughtError (/Users/bastian/instana/code/nodejs/packages/collector/test/uncaught/apps/rethrow.js:8:9)
    at Object.<anonymous> (/Users/bastian/instana/code/nodejs/packages/collector/test/uncaught/apps/rethrow.js:11:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
    at internal/main/run_main_module.js:17:11

> nvm use 12.6.0 && node rethrow

Now using node v12.6.0 (npm v6.9.0)
/Users/bastian/instana/code/nodejs/packages/collector/test/uncaught/apps/rethrow.js:4
  throw err;
  ^

Error: Boom

>

Commits 0fd6524 and 5b92eb4 might be related to this change in behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.errorsIssues and PRs related to JavaScript errors originated in Node.js core.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions