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

prepareStackTrace doesn't work on error thrown within prepareStackTrace handler #53618

Closed
orinatic opened this issue Jun 28, 2024 · 2 comments
Closed

Comments

@orinatic
Copy link

Version

v20.8.1

Platform

Linux ushanka-housing 6.5.0-1023-oem #24-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 14:26:31 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

Error

What steps will reproduce the bug?

Run

function f1(e, trace) {
  Error.prepareStackTrace = f2
  console.log(Error("e2").stack)
  return "F1"
}

function f2(e, trace) {
  return "F2"
}

Error.prepareStackTrace = f1
console.log(Error("e1").stack)

How often does it reproduce? Is there a required condition?

This will repro 100% of the time

What is the expected behavior? Why is that the expected behavior?

We should see

"F2"
"F1"

Inside the f1 handler, we set Error.prepareStackTrace. It makes sense that the original error (e1) isn't affected, since it's already being handled, but e2 should use the newest Error.prepareStackTrace function.

What do you see instead?

Error: e2
    at Function.f1 (/home/eli/code/nodejs-agent/tests/one_offs/prepareStackTrace_nest.js:4:15)
    at maybeOverridePrepareStackTrace (node:internal/errors:141:29)
    at prepareStackTrace (node:internal/errors:115:5)
    at Object.<anonymous> (/home/eli/code/nodejs-agent/tests/one_offs/prepareStackTrace_nest.js:14:24)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47
F1

So it looks like not only is the F2 handler being ignored, the F1 handler is as well

Additional information

Maybe this is intentional to help with debugging?

I can see why you would probably want a non-custom error if there's an error in your prepareStackTrace by default, but it would be really nice if a new prepareStackTrace handler was honored if set.

Maybe?

@climba03003
Copy link
Contributor

The same is happen on v8 (also Chrome).
I believe if you need to change the behavior, you should file issue to v8 instead of here.

@benjamingr
Copy link
Member

Correct, this needs to be filed upstream in V8 (and I suspect it's intentional) - https://crbug.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants