- Notifications
You must be signed in to change notification settings - Fork 2k
Don’t patch Error.prepareStackTrace if --enable-source-maps is used.#5403
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
STRd6 commented Apr 1, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
STRd6 commented Apr 1, 2022
It looks like |
STRd6 commented Apr 1, 2022
Tests also pass on |
STRd6 commented Apr 1, 2022
Node |
Error.prepareStackTrace if --enable-source-maps is used.GeoffreyBooth commented Apr 3, 2022
If you don’t mind updating with the latest |
- Added check to not patch `Error.prepareStackTrace` if it has already been patched by another library. - Always attach inline source maps if `--enable-source-map` is set. - Added some basic tests for stack trace.
50dfa8e to 85cc164CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
test/sourcemap.coffee Outdated
| ifprocess.version.split(".")[0] !="v12" | ||
| test"native source maps", -> | ||
| newPromise (resolve, reject) -> | ||
| proc=spawn"node", [ |
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.
You can use child_process.fork to specifically spawn Node child processes: https://nodejs.org/api/child_process.html#:~:text=The%20child_process.fork()%20method%20is%20a%20special%20case%20of%20child_process.spawn()%20used%20specifically%20to%20spawn%20new%20Node.js%20processes.
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.
Is there a reason you used fork in the above test but spawn here?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Geoffrey Booth <[email protected]>
STRd6 commented Apr 4, 2022
I'm pretty happy with how this is functionally. There's some more clean up and testing that can be followed up with but I'm fairly confident that this will maintain the existing functionality while fixing the two cases where patching |
STRd6 commented Apr 4, 2022
There's actually one other case that this doesn't address correctly yet: when The fix is to move the logic into |
`path.relative` doesn't include a trailing separator which causes source maps to have an inaccurate file path when using `--enable-source-maps` in node.
GeoffreyBooth commented Apr 7, 2022
Please let me know when you’re done working on this branch and I’ll review it again. Please don’t forget the style notes (single-quoted strings unless interpolating, avoid single-character variables). |
STRd6 commented Apr 8, 2022
I'll get a few more updates in and summarize the changes as well over the next few days. |
Uh oh!
There was an error while loading. Please reload this page.
STRd6 commented Apr 11, 2022
@GeoffreyBooth this is ready for review now. It's a bit larger than I originally anticipated. Please ask any questions you have so I can better document exactly what changed and how things work. I'm not sure why the CI is flaky on windows but I should look into that before this is merged. |
GeoffreyBooth left a comment
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.
This is very good! A few notes here and there and this should be ready to land.
Does this fix #5216 by chance? From a quick search of open issues, that appears to be the only other open issue related to source maps.
| exports.anonymousFileName=do-> | ||
| n=0 | ||
| -> | ||
| "<anonymous-#{n++}>" |
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.
Should this use square brackets (like [anonymous-0]) to match [stdin]?
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.
It was previously <anonymous> which matches the "filename" of Node's eval.
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.
which matches the “filename” of Node’s
eval.
That’s fine; do you mind sharing where you see that in Node?
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.
node Welcome to Node.js v17.9.0. Type ".help" for more information. > eval("throw new Error") Uncaught Error at eval (eval at <anonymous> (REPL1:1:1), <anonymous>:1:7) > Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
test/sourcemap.coffee Outdated
| ifprocess.version.split(".")[0] !="v12" | ||
| test"native source maps", -> | ||
| newPromise (resolve, reject) -> | ||
| proc=spawn"node", [ |
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.
Is there a reason you used fork in the above test but spawn here?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
STRd6 commented Apr 17, 2022
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
STRd6 commented Apr 18, 2022
One thing to note is that though this does fix a bug/unexpected behavior it could be considered a breaking change to how CoffeeScript=require('coffeescript')CoffeeScript.patchStackTrace() |
GeoffreyBooth commented Apr 18, 2022
I thought the intent was to keep the current behavior unless |
STRd6 commented Apr 18, 2022
I think that the correct long term solution is to not do anything drastic to people's environments when If that is too breaking a change to go out soon then I can update the PR to also have |
GeoffreyBooth commented Apr 18, 2022
I thought the current behavior was not to patch unless If so, yeah, we should restrict the patching to |
STRd6 commented Apr 18, 2022
👍 The current behavior in coffeescript/src/coffeescript.coffee Line 368 in 76cf769
This PR restricts the patching to |
| sourceURL="//# sourceURL=#{filename}" | ||
| js="#{js}\n#{sourceMapDataURI}\n#{sourceURL}" |
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.
FYI, not as part of this PR but related: #5237
GeoffreyBooth commented Apr 19, 2022
Thanks @STRd6 and congrats! We’re overdue for a release, are there any other PRs you’d like to land soon or should I prepare a release for later this week? |
STRd6 commented Apr 19, 2022
@GeoffreyBooth thanks for the review! I don't have anything else ready to land so release when ready 👍 |
Fixes#5382 Don't monkey patch
Error.prepareStackTraceif--enable-source-mapsis used.This ended up being kind of a chonker but I'm pretty happy with the overall structure. Also a little terrified with how much this touches, as well as a little relieved that there are tons of existing tests to catch regressions 😅
In summary:
require('coffeescript')no longer patchesError.prepareStackTrace. People mustrequire('coffeescript/register')to opt-in.CoffeeScript.runalready does this which will maintain the existingcoffeecli experience.Error.prepareStackTraceis not patched if another library has already patched it even when callingrequire('coffeescript/register').Error.prepareStackTracepatching incoffeescript.coffeeis now exported rather than applied automatically.register.coffeeimports it. The browser docs also call it directly.sourcemap.coffee(not sure if this is the ideal place).<anonymous>name.getSourceMapandregisterCompiledmuch simpler.registerCompiledso other tools can cache source maps and hook into CoffeeScript stack remapping (CoffeeCoverage, etc.)helpers.syntaxErrorToStringto print[stdin]for<anonymous.*files as well as files with undefined file name to match the existing tests.index.coffeeCoffeeScript.runsetinlineMapto be true and set the baseoption.filenameto match themainModulefilename.TODO
CoffeeScript.compilealways caches source maps if present. This makes the call toregisterCompiledinregister.coffeeredundant. Need to do some thinking about how to untangle this../bin/coffee --nodejs --enable-source-maps test/importing/error.coffee(Looks like file path is currently incorrect:C:\Users\duder\Documents\GitHub\coffeescript\test\..test\importing\error.coffee:3:9)