Skip to content
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

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

Closed
basti1302 opened this issue Jul 5, 2019 · 1 comment · Fixed by #28562
Closed
Labels
confirmed-bug Issues with confirmed bugs. errors Issues and PRs related to JavaScript errors originated in Node.js core.

Comments

@basti1302
Copy link

  • 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.

@basti1302 basti1302 changed the title Stack gets lost in Node.js 12.6.0 when rethrowing from uncaught exception handler Stack trace gets lost in Node.js 12.6.0 when rethrowing from uncaught exception handler Jul 5, 2019
@addaleax
Copy link
Member

addaleax commented Jul 5, 2019

/cc @joyeecheung

@addaleax addaleax added confirmed-bug Issues with confirmed bugs. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Jul 5, 2019
cjihrig added a commit to cjihrig/node that referenced this issue Jul 7, 2019
This commit allows fatal exceptions to be enhanced so that
exceptions thrown from an unhandledException handler have
the stack attached properly.

PR-URL: nodejs#28562
Fixes: nodejs#28550
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
targos pushed a commit that referenced this issue Jul 20, 2019
This commit allows fatal exceptions to be enhanced so that
exceptions thrown from an unhandledException handler have
the stack attached properly.

PR-URL: #28562
Fixes: #28550
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. errors Issues and PRs related to JavaScript errors originated in Node.js core.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants