-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Error.prepareStackTrace not called when --enable-source-maps #29994
Comments
this isn't exactly a bug, more like a known limitation. |
Well, like I said,
If it's a known limitation, is it documented somewhere I'm missing? |
I've hit this while trying |
cc @bcoe The question is even if we call |
I think if we can't figure out how to make them work together right now we should fix the docs and mention that they do not work together at the moment (that was my review request in #29564 (comment)) |
this seems like a nice opportunity to guage how much the ecosystem can be weened off of prepareStackTrace, although it's regrettable we don't have something to replace it with. |
I'm not sure if someone has a method to look through the npm ecosystem to see the usage. This report came in because, for example, Express will not even start with the command line enabled. Even if it started, it's hard to know what uses it at runtime. There are modules I'm aware of that their entire existence depends on this API like https://www.npmjs.com/package/callsites (160 dependents), https://www.npmjs.com/package/callsite (394 dependents), etc. and also modules that use it for some of their functionality like https://www.npmjs.com/package/resolve (4,385 dependents). |
I think that's what |
One option would be that we move the logic outside of Perhaps we should just update the documentation to indicate that it does not work in conjunction with |
@dougwilson @joyeecheung @devsnek before I update docs, should we consider adding this logic to our source-map support?
We could even consider not returning, and attempting to rework the stack trace after calling the @dougwilson what are your thoughts:
|
I think if we want to support prepareStackTrace with source maps, we should create some fake call sites and pass them. |
So as for what to do, from what I can tell about a lot of this modules on npm that use this, they typically want to access the stack information (vs format it). If I were to advocate for something specifically, I would probably say in the following order:
I'm not 100% on either of those, as I can see merits in either one. It would be cool to hear from other folks who use this as well in userland; I'm just the unfortunate first victim due to the popularity of Express |
I don't love simply adding the new call sites, because I think it would become harder to differentiate between the original source and transpiled source, I feel there's value in the formatting of:
Perhaps the best of both worlds would be: // Polyfill of V8's Error.prepareStackTrace API.
// https://crbug.com/v8/7848
// `globalThis` is the global that contains the constructor which
// created `error`.
if (typeof globalThis.Error.prepareStackTrace === 'function') {
addFakeCallSites(trace)
return globalThis.Error.prepareStackTrace(error, trace);
}
printPrettyStackTrace(); |
It is possible that the user actually wants the original callsites e.g. if they want to parse th original stack trace and read the files, IIRC that's what our assert module does (did?) to annotate the diff of objects. Then if the original file does not exist on the machine that runs the code this polyfill still breaks things. If we rush into adding some support that do not fit the actual use cases well it might result in another maintainance burden like what |
Can we mayble simply add another property to the call site object, e.g. Either way, I think we’ll have to consider |
I am very strongly against adding any API surface to any part of prepareStackTrace. |
@devsnek I’m not a fan of that idea, but I’d be perfectly happy with just making |
document the fact that --enable-source-maps and prepareStackTrace are incompatible, see nodejs#29994
#30046 is good to document how it works now, but I think that while we are figuring out how to interop
Is this technically possible? |
yeah, you would just add the source map stuff below those checks in errors.js. I just really don't like removing something as useful as source map info for this annoying legacy api. |
Sure, but the uses of the stack trace API that I have seen in the wild and block our flag for example in Express replace the function temporarily and put it back just after doing their thing so it wouldn't affect source map info |
Is there some other API available to get a non stringified stack trace? |
@Flarna not at the moment. There is https://github.com/tc39/proposal-error-stacks which is going to eventually be something, but not any time soon. |
I have not digged into the FYI the use case we have in our monitoring regarding this: We correlate the function name, location seen on As this correlation is done by using hashes the strings we extract have to match. It would be really cool to get mapped info in all this cases if available. Seems the current implemenation effects only stack traces therefore the option to get it unmapped everywhere would be good. |
👋 There's also discussion in this PR about how to expose source maps for upstream tooling (would appreciate your thoughts). @devsnek should we hold off on closing this until the next Node.js release I suppose? |
Will this be available in (backported to?) Node 12 LTS, or only in 13+? (As someone currently stuck with 12, because it’s LTS, I think it would be lovely to see it backported, if necessary.) |
I have tested this fix in |
It seems that when
--enable-source-maps
is enabled, the way errors work is altered. For example, a globalError.prepareStackTrace
function is no longer called as part of the process.I know
--enable-source-maps
is experimental based on the docs, but cannot find any specific information on, for example, if this is an expected change to runtime behavior or not.Just glancing around at the source code, I believe that
internal/errors.js
is what is calling theError.prepareStackTrace
when defined, but the command line flag replaces the stack trace implementation to one that does not callError.prepareStackTrace
any longer.The text was updated successfully, but these errors were encountered: