-
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
src,lib: print source map error source on demand #43875
Conversation
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.
I really like this approach 🎉
One thing I noticed, was the addition of kSourceURLMagicComment
, I think this relates to evaluated code? If this addresses an issue we didn't catch with your last PR, perhaps we should add an additional test for it?
Local<Value> argv[] = {script_resource_name, | ||
v8::Int32::New(isolate, linenum), | ||
v8::Int32::New(isolate, columnum)}; | ||
MaybeLocal<Value> maybe_ret = env->get_source_map_error_source()->Call( |
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.
I like this approach a lot 👍 good idea moving this behaviour into C++ land.
The source context is not prepended to the value of the `stack` property when the source map is not enabled. Rather than prepending the error source context to the value of the `stack` property unconditionally, this patch aligns the behavior and only prints the source context when the error is not handled by userland (e.g. fatal errors). Also, this patch fixes that when source-map support is enabled, the error source context is not pointing to where the error was thrown.
6a97b7f
to
1ef283d
Compare
@bcoe thank you for the suggestion! Updated with stricter nullish check. :) |
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.
If you still have benchmarks setup, mind testing this branch against HEAD, for the source-map benchmarks?
- To make sure moving responsiblities into C++ didn't hit performance in any ways.
- To see if we actually improved performance in some cases.
@nodejs/cpp-reviewers would be good to have someone take a look at this PR. |
@legendecas I'd make the case that, even though you could squint and call this a breaking change, perhaps it's worth landing in a patch, when we weigh the performance benefits against the likeliness of breaking people:
This might be a question worth bringing to @nodejs/tsc |
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
Have we got a measure of the performance benefit?
I would recommend we land it on Node.js v18 in a minor release but do not backport to Node v16. Having it in Node.js v19 push one year and a few month widespread adoption of this change.
@nodejs/tsc would you be willing to land this in Node v18 with do-not-backport flags for v16? |
Updated with a benchmark on accessing the
|
16aab97
to
d3efe87
Compare
@mcollina any specific reason why it should not be backported to e.g., v16? |
Possible breakages. Maybe we could just label it as "backing" and reevaluate in a few months. |
Refs: #43875 PR-URL: #44019 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Feng Yu <[email protected]>
The source context is not prepended to the value of the `stack` property when the source map is not enabled. Rather than prepending the error source context to the value of the `stack` property unconditionally, this patch aligns the behavior and only prints the source context when the error is not handled by userland (e.g. fatal errors). Also, this patch fixes that when source-map support is enabled, the error source context is not pointing to where the error was thrown. PR-URL: #43875 Fixes: #43186 Fixes: #41541 Reviewed-By: Ben Coe <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Refs: #43875 PR-URL: #44019 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Feng Yu <[email protected]>
Notable changes: bootstrap: implement run-time user-land snapshots via --build-snapshot and --snapshot-blob This patch introduces `--build-snapshot` and `--snapshot-blob` options for creating and using user land snapshots. To generate a snapshot using snapshot.js as an entry point and write the snapshot blob to snapshot.blob: ```bash echo "globalThis.foo = 'I am from the snapshot'" > snapshot.js node --snapshot-blob snapshot.blob --build-snapshot snapshot.js ``` To restore application state from snapshot.blob, with index.js as the entry point script for the deserialized application: ```bash echo "console.log(globalThis.foo)" > index.js node --snapshot-blob snapshot.blob index.js ``` Users can also use the `v8.startupSnapshot` API to specify an entry point at snapshot building time, thus avoiding the need of an additional entry script at deserialization time: ```bash echo "require('v8').startupSnapshot.setDeserializeMainFunction(() => console.log('I am from the snapshot'))" > snapshot.js node --snapshot-blob snapshot.blob --build-snapshot snapshot.js node --snapshot-blob snapshot.blob ``` Contributed by Joyee Cheung in #38905 Other notable changes: * crypto: * (SEMVER-MINOR) allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) #44201 * (SEMVER-MINOR) allow zero-length secret KeyObject (Filip Skokan) #44201 * doc: * add MoLow to collaborators (Moshe Atlow) #44214 * add ErickWendel to collaborators (Erick Wendel) #44088 * http: * (SEMVER-MINOR) make idle http parser count configurable (theanarkh) #43974 * net: * (SEMVER-MINOR) add local family (theanarkh) #43975 * src: * (SEMVER-MINOR) add detailed embedder process initialization API (Anna Henningsen) #44121 * (SEMVER-MINOR) print source map error source on demand (Chengzhong Wu) #43875 * tls: * (SEMVER-MINOR) pass a valid socket on `tlsClientError` (Daeyeon Jeong) #44021 * worker: * deprecate `--trace-atomics-wait` (Keyhan Vakil) #44093
The source context is not prepended to the value of the `stack` property when the source map is not enabled. Rather than prepending the error source context to the value of the `stack` property unconditionally, this patch aligns the behavior and only prints the source context when the error is not handled by userland (e.g. fatal errors). Also, this patch fixes that when source-map support is enabled, the error source context is not pointing to where the error was thrown. PR-URL: #43875 Fixes: #43186 Fixes: #41541 Reviewed-By: Ben Coe <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Refs: #43875 PR-URL: #44019 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Feng Yu <[email protected]>
Notable changes: * bootstrap: * implement run-time user-land snapshots via --build-snapshot and --snapshot-blob (Joyee Cheung) in #38905 * crypto: * (SEMVER-MINOR) allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) #44201 * (SEMVER-MINOR) allow zero-length secret KeyObject (Filip Skokan) #44201 * deps: * upgrade npm to 8.18.0 (npm team) #44263 - Adds a new npm query cmd * doc: * add Erick Wendel to collaborators (Erick Wendel) #44088 * add MoLow to collaborators (Moshe Atlow) #44214 * deprecate --trace-atomics-wait (Keyhan Vakil) #44093 * http: * (SEMVER-MINOR) make idle http parser count configurable (theanarkh) #43974 * net: * (SEMVER-MINOR) add local family (theanarkh) #43975 * src: * (SEMVER-MINOR) print source map error source on demand (Chengzhong Wu) #43875 * tls: * (SEMVER-MINOR) pass a valid socket on tlsClientError (Daeyeon Jeong) #44021 PR-URL: TBD
Notable changes: * bootstrap: * implement run-time user-land snapshots via --build-snapshot and --snapshot-blob (Joyee Cheung) in #38905 * crypto: * (SEMVER-MINOR) allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) #44201 * (SEMVER-MINOR) allow zero-length secret KeyObject (Filip Skokan) #44201 * deps: * upgrade npm to 8.18.0 (npm team) #44263 - Adds a new npm query cmd * doc: * add Erick Wendel to collaborators (Erick Wendel) #44088 * add MoLow to collaborators (Moshe Atlow) #44214 * deprecate --trace-atomics-wait (Keyhan Vakil) #44093 * http: * (SEMVER-MINOR) make idle http parser count configurable (theanarkh) #43974 * net: * (SEMVER-MINOR) add local family (theanarkh) #43975 * src: * (SEMVER-MINOR) print source map error source on demand (Chengzhong Wu) #43875 * tls: * (SEMVER-MINOR) pass a valid socket on tlsClientError (Daeyeon Jeong) #44021 PR-URL: #44353
Notable changes: * bootstrap: * implement run-time user-land snapshots via --build-snapshot and --snapshot-blob (Joyee Cheung) in #38905 * crypto: * (SEMVER-MINOR) allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) #44201 * (SEMVER-MINOR) allow zero-length secret KeyObject (Filip Skokan) #44201 * deps: * upgrade npm to 8.18.0 (npm team) #44263 - Adds a new npm query cmd * doc: * add Erick Wendel to collaborators (Erick Wendel) #44088 * add theanarkh to collaborators (theanarkh) #44131 * add MoLow to collaborators (Moshe Atlow) #44214 * add cola119 to collaborators (cola119) #44248 * deprecate --trace-atomics-wait (Keyhan Vakil) #44093 * http: * (SEMVER-MINOR) make idle http parser count configurable (theanarkh) #43974 * net: * (SEMVER-MINOR) add local family (theanarkh) #43975 * src: * (SEMVER-MINOR) print source map error source on demand (Chengzhong Wu) #43875 * tls: * (SEMVER-MINOR) pass a valid socket on tlsClientError (Daeyeon Jeong) #44021 PR-URL: #44353
Notable changes: * bootstrap: * implement run-time user-land snapshots via --build-snapshot and --snapshot-blob (Joyee Cheung) in #38905 * crypto: * (SEMVER-MINOR) allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) #44201 * (SEMVER-MINOR) allow zero-length secret KeyObject (Filip Skokan) #44201 * deps: * upgrade npm to 8.18.0 (npm team) #44263 - Adds a new npm query cmd * doc: * add Erick Wendel to collaborators (Erick Wendel) #44088 * add theanarkh to collaborators (theanarkh) #44131 * add MoLow to collaborators (Moshe Atlow) #44214 * add cola119 to collaborators (cola119) #44248 * deprecate --trace-atomics-wait (Keyhan Vakil) #44093 * http: * (SEMVER-MINOR) make idle http parser count configurable (theanarkh) #43974 * net: * (SEMVER-MINOR) add local family (theanarkh) #43975 * src: * (SEMVER-MINOR) print source map error source on demand (Chengzhong Wu) #43875 * tls: * (SEMVER-MINOR) pass a valid socket on tlsClientError (Daeyeon Jeong) #44021 PR-URL: #44353
} | ||
} | ||
} | ||
if (sourceMap && sourceMap.data) { | ||
return new SourceMap(sourceMap.data); | ||
} | ||
return undefined; | ||
return null; |
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.
Isn't this a breaking change? AVA for example relies on this that it returns undefined here.
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 you open a separate issue? This looks like something unintended that we can fix.
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.
Notable changes: * bootstrap: * implement run-time user-land snapshots via --build-snapshot and --snapshot-blob (Joyee Cheung) in nodejs#38905 * crypto: * (SEMVER-MINOR) allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) nodejs#44201 * (SEMVER-MINOR) allow zero-length secret KeyObject (Filip Skokan) nodejs#44201 * deps: * upgrade npm to 8.18.0 (npm team) nodejs#44263 - Adds a new npm query cmd * doc: * add Erick Wendel to collaborators (Erick Wendel) nodejs#44088 * add theanarkh to collaborators (theanarkh) nodejs#44131 * add MoLow to collaborators (Moshe Atlow) nodejs#44214 * add cola119 to collaborators (cola119) nodejs#44248 * deprecate --trace-atomics-wait (Keyhan Vakil) nodejs#44093 * http: * (SEMVER-MINOR) make idle http parser count configurable (theanarkh) nodejs#43974 * net: * (SEMVER-MINOR) add local family (theanarkh) nodejs#43975 * src: * (SEMVER-MINOR) print source map error source on demand (Chengzhong Wu) nodejs#43875 * tls: * (SEMVER-MINOR) pass a valid socket on tlsClientError (Daeyeon Jeong) nodejs#44021 PR-URL: nodejs#44353
The source context is not prepended to the value of the `stack` property when the source map is not enabled. Rather than prepending the error source context to the value of the `stack` property unconditionally, this patch aligns the behavior and only prints the source context when the error is not handled by userland (e.g. fatal errors). Also, this patch fixes that when source-map support is enabled, the error source context is not pointing to where the error was thrown. PR-URL: nodejs#43875 Fixes: nodejs#43186 Fixes: nodejs#41541 Reviewed-By: Ben Coe <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Refs: nodejs#43875 PR-URL: nodejs#44019 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Feng Yu <[email protected]>
Notable changes: * bootstrap: * implement run-time user-land snapshots via --build-snapshot and --snapshot-blob (Joyee Cheung) in nodejs#38905 * crypto: * (SEMVER-MINOR) allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) nodejs#44201 * (SEMVER-MINOR) allow zero-length secret KeyObject (Filip Skokan) nodejs#44201 * deps: * upgrade npm to 8.18.0 (npm team) nodejs#44263 - Adds a new npm query cmd * doc: * add Erick Wendel to collaborators (Erick Wendel) nodejs#44088 * add theanarkh to collaborators (theanarkh) nodejs#44131 * add MoLow to collaborators (Moshe Atlow) nodejs#44214 * add cola119 to collaborators (cola119) nodejs#44248 * deprecate --trace-atomics-wait (Keyhan Vakil) nodejs#44093 * http: * (SEMVER-MINOR) make idle http parser count configurable (theanarkh) nodejs#43974 * net: * (SEMVER-MINOR) add local family (theanarkh) nodejs#43975 * src: * (SEMVER-MINOR) print source map error source on demand (Chengzhong Wu) nodejs#43875 * tls: * (SEMVER-MINOR) pass a valid socket on tlsClientError (Daeyeon Jeong) nodejs#44021 PR-URL: nodejs#44353
The source context is not prepended to the value of the
stack
property when the source map is not enabled. Rather than prepending the error source context to the value of thestack
property unconditionally, this PR aligns the behavior and only prints the source context when the error is not handled by userland (e.g. fatal errors).Also, this PR fixes that when source-map support is enabled, the error source context is not pointing to where the error was thrown. For a source file "test.js" like:
The source context for the thrown error should be:
Fixes: #43186
Fixes: #41541