-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
errors: print original exception context #33491
Conversation
As a general rule, v8::Message is generated from the location of throw, and the error's stack is generated from the location of the error. The v8::Message might sometimes point to the error location instead if it failed to figure out the throw location. |
@devsnek do you think we should be clever, and even just grep for the |
@bcoe i think its okay to use the error position. alternatively, you could store the message position info on the error in c++ (like how we store decorations) so its available in the js prepareStackTrace callback. |
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.
As a general observation, having an environment-wide flag that toggles the behavior doesn't seem like a good idea. Wouldn't you want to distinguish on whether the script contains a source map URL or not?
You can query the v8::Message
object to find out if it has one:
const bool has_source_map_url =
!message->GetScriptOrigin().SourceMapUrl().IsEmpty();
@bnoordhuis It does, however, present the issue that if you haven't run a file with Should we check both values (whether source maps are enabled, and whether the script has a source map), and only annotate the error in |
@bnoordhuis using your suggestion as a starting point, we now only apply the new
|
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.
@addaleax I know you've also worked in this file, any thoughts (maybe this is an issue we don't care about).
Not really any thoughts beyond that this seems useful and I’m happy to see it :)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
LGTM. Just left a suggestion to improve unicode support and maybe another test file was meant to be added?
@BridgeAR I opted for using fixture based testing, my thinking being that it's actually a pretty elegant way to assert against the whole stack output. tldr; those are tabs in > const text = fs.readFileSync('test/message/source_map_reference_error_tabs.out', 'utf8')
undefined
> text
'*tabs.coffee:26\n' +
'\talert "I knew it!"\n' +
'\t^\n' + |
@BridgeAR can you recommend an error message we could throw that would exercise your unicode improvements, I think this would be a great addition to the test suite. Well I'm extending on the test suite, any thoughts on a transpiler I haven't used yet 😆 We've used babel, TypeScript, uglify, CoffeeScript, Istanbul. |
@bcoe I mostly use the following characters to verify unicode support:
Using these in the error message should be sufficient. |
@BridgeAR take a look 👍 I noticed that it's actually more accurate with source maps than without now (the message displayed for |
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.
LGTM % comments. Nice work, @bcoe.
dae507e
to
a0b9de9
Compare
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.
Awesome work! Still LGTM, just left two nits.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
When --enable-source-maps is set, the error context displayed above the stack trace now shows original source rather than transpiled.
This comment has been minimized.
This comment has been minimized.
When --enable-source-maps is set, the error context displayed above the stack trace now shows original source rather than transpiled. PR-URL: #33491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Landed in 458677f |
@bcoe would you mind opening a manual backport for this into |
When --enable-source-maps is set, the error context displayed above the stack trace now shows original source rather than transpiled. PR-URL: nodejs#33491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
When --enable-source-maps is set, the error context displayed above the stack trace now shows original source rather than transpiled. Backport-PR-URL: nodejs#37700 PR-URL: nodejs#33491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
When --enable-source-maps is set, the error context displayed above the stack trace now shows original source rather than transpiled. Backport-PR-URL: #37700 PR-URL: #33491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
When --enable-source-maps is set, the error context displayed above the stack trace now shows original source rather than transpiled. Backport-PR-URL: #37700 PR-URL: #33491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
When --enable-source-maps is set, the error context displayed
above the stack trace now shows original source rather than
transpiled.
When
--enable-source-maps
is set, annotate the top of the stack trace with the original source, rather than the ugly transpiled source:before:
after:
Open questions
The logic in
node_errors.cc
is a little magical to me, specifically I'm trying to figure out how it's placing the^
under thethrow
, rather than under theError
(which is where the stack trace points).@addaleax I know you've also worked in this file, any thoughts (maybe this is an issue we don't care about).
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes