-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
src, util: move error decoration to native #19815
Conversation
195a833
to
32f1f89
Compare
There is a spurious package-lock file added to this PR. |
src/node.cc
Outdated
CHECK(err_obj->SetPrivate( | ||
env->context(), | ||
env->error_decorated_private_symbol(), | ||
v8::True(env->isolate())).FromMaybe(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified to:
err_obj->SetPrivate(env->context(),
env->error_decorated_private_symbol(),
v8::True(env->isolate())).FromJust();
Does this decorate an error if the Is there a way to opt-out of an error being decorated so that this won't clobber existing decorating user-land may do to stacks? |
@jdalton I'm like 97% sure this pr has so far only changed observable behaviour for modules, not scripts. that being said if anyone feels like throwing test cases at it that would be cool |
This needs a rebase. |
anyone have any opinions on something like |
A global flag is nice, but a programmatic way to opt-out per error would be better. For example: foo.mjsconst e = new Error
e.stack = "DECORATED\n" + e.stack
throw e Will produce:
Which is decorating an already decorated error. If there was an API to specify that an error is already decorated that would be great. The expected output of opting-out of the built-in decorator is
Something like |
@jdalton funny you ask for a programmatic way to opt out, as i've just found out over the last few hours the only proper way for node to do this is via Error.prepareStackTrace. i'm hesitant because of that to continue with this pr, but if people feel like the ecosystem will survive node setting Error.prepareStackTrace i'd like to continue. it would have the added benefit of moving node's error decoration to js which should speed things up. its also worth noting that at the current time node doesn't really support opting out of decoration. currently opting out looks like this: https://github.com/devsnek/node-noasi/blob/master/index.js#L45 |
I'm aware of
Correct. A more legit way would be great! |
@jdalton assuming that the v8 embedder has set Error.prepareStackTrace, a user can just change the override while their stack trace is being generated. this is already a pretty common practice in userland. |
Ah ya, though that's more of a global solution, so not great for per error opt-outs (package use). |
i've also mentioned this in the error stacks proposal for tc39: tc39/proposal-error-stacks#20 (comment) and i opened a feature request for something from v8's c++ api: https://bugs.chromium.org/p/v8/issues/detail?id=7637 |
i think i'll just close this, those two linked issues are plenty for tracking |
@ChALkeR would it be possible to run a gzemnid for specifically code that does |
Fixes: #19783
Fixes: #19763
This moves the burden of decorating error stacks to TryCatch, which is always used in this case, so we know the stacks will always be decorated. I'm going to benchmark this soonish, and a bunch of message tests have to be updated
/cc @nodejs/diagnostics @nodejs/performance
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes