Skip to content
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

process: add source-map support to stack traces #29564

Closed
wants to merge 8 commits into from

Conversation

@bcoe
Copy link
Member

commented Sep 15, 2019

This uses SourceMap.js (shipped with V8) and the cache developed in #28960, to add source-map support to stack traces.

How it works:

If you run your program with the flag --source-map-support, and a source-map is found and cached for a file, stack traces are annotated with both the original and transpiled source positions:

Error: goodbye
    at  /Users/bencoe/oss/node-1/test/fixtures/source-map/inline-throw.min.js:1:43
         -> /Users/bencoe/oss/node-1/test/fixtures/source-map/throw.js:8:2
    at  Immediate.<anonymous> (/Users/bencoe/oss/node-1/test/fixtures/source-map/inline-throw.min.js:1:60)
         -> /Users/bencoe/oss/node-1/test/fixtures/source-map/throw.js:8:2
    at  processImmediate (internal/timers.js:439:21)

Providing both the original and transpiled source if possible.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
  • test with source-map generated by uglify.
  • test with source-map generated by babel.
  • test with source-map generated by TypeScript.
  • test with source-map generated by nyc/Istanbul.

This grows out of continuing conversation here.

And relies on #28960, which I would ideally like to land first. (landed).

lib/internal/errors.js Outdated Show resolved Hide resolved
lib/internal/errors.js Outdated Show resolved Hide resolved
lib/internal/errors.js Outdated Show resolved Hide resolved
lib/internal/modules/cjs/loader.js Outdated Show resolved Hide resolved
lib/internal/source_map/source_map.js Show resolved Hide resolved
doc/api/cli.md Outdated Show resolved Hide resolved
@benjamingr

This comment has been minimized.

Copy link
Member

commented Sep 15, 2019

Code LGTM with devsnek's comments addressed. I'll also play with this locally a bit and see if it behaves consistently. Thanks for this this is a big usability improvement in core for a lot of our users!

(Note this will probably have to be semver-major and with a CITGM run because it changes all errors and some libraries parse them)

@bcoe

This comment has been minimized.

Copy link
Member Author

commented Sep 15, 2019

@benjamingr do you think a major is necessary, even though someone will opt in with --experimental-source-maps, I'm thinking if we drop the experimental we'd probably just switch to --enable-source-maps and keep it opt in?

Open to other people's thinking on this.

@ljharb

This comment has been minimized.

Copy link
Member

commented Sep 15, 2019

While behind an experimental flag, I’d expect no changes to precipitate a major.

@joyeecheung

This comment has been minimized.

Copy link
Member

commented Sep 16, 2019

If it's opt-in via flags I don't think this need to be semver-major. BTW I think it's fine to just use --enable-source-maps from the start with an experimental warning.

doc/api/cli.md Outdated Show resolved Hide resolved
lib/internal/errors.js Outdated Show resolved Hide resolved
lib/internal/errors.js Outdated Show resolved Hide resolved
@benjamingr

This comment has been minimized.

Copy link
Member

commented Sep 16, 2019

Sorry for being unclear: I do not think this needs to be major with the flag but I do eventually think Node.js should turn this on by default and that change should be semver-major.

+1 for Joyee's idea of doing --enable-source-maps, I would even take this one step further because I'd like this to be opt-out eventually rather than opt-in and I'd prefer:

--source-maps=true which eventually would be the default and users would be able to opt out with --source-maps=false

@Trott Trott force-pushed the nodejs:master branch from 1ecc406 to 49cf67e Sep 17, 2019
@bcoe bcoe referenced this pull request Sep 19, 2019
7 of 7 tasks complete
@bcoe bcoe force-pushed the bcoe:source-map-support branch 2 times, most recently from fe2171b to 3ee0717 Sep 22, 2019
@bcoe

This comment has been minimized.

Copy link
Member Author

commented Sep 22, 2019

@LinusU I'm wondering if you have any feedback, as we start to build this out; I imagine you've bumped into some interesting edge cases building source-map-support.

@bcoe bcoe force-pushed the bcoe:source-map-support branch 3 times, most recently from 8238a97 to ffddaf1 Sep 27, 2019
@bcoe bcoe marked this pull request as ready for review Sep 28, 2019
@devsnek devsnek removed the author ready label Oct 4, 2019
Copy link
Member

left a comment

Yes.

'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
base64Map = {};
for (let i = 0; i < base64Digits.length; ++i)
base64Map[base64Digits.charAt(i)] = i;

This comment has been minimized.

Copy link
@ljharb

ljharb Oct 4, 2019

Member
Suggested change
base64Map[base64Digits.charAt(i)] = i;
base64Map[base64Digits[i]] = i;

charAt is needed for maximum back compat, but not needed here.

However, I think you can do Object.fromEntries(Object.entries(base64Digits)) and replace this entire loop.

@bcoe bcoe added the author ready label Oct 4, 2019
@nodejs nodejs deleted a comment from nodejs-github-bot Oct 4, 2019
@bcoe bcoe force-pushed the bcoe:source-map-support branch from 38eb146 to ae47642 Oct 5, 2019
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment has been minimized.

Copy link

commented Oct 5, 2019

@nodejs-github-bot

This comment has been minimized.

bcoe added a commit that referenced this pull request Oct 6, 2019
PR-URL: #29564
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@bcoe

This comment has been minimized.

Copy link
Member Author

commented Oct 6, 2019

Landed in e1e2f66

@bcoe bcoe closed this Oct 6, 2019
@bcoe bcoe deleted the bcoe:source-map-support branch Oct 6, 2019
BridgeAR added a commit that referenced this pull request Oct 9, 2019
PR-URL: #29564
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit that referenced this pull request Oct 10, 2019
Notable changes:

* build:
  * Add `--force-context-aware` flag to prevent usage of native node
    addons that aren't context aware
    #29631
* deprecations:
  * Add documentation-only deprecation for `process._tickCallback()`
    #29781
* esm:
  * Using JSON modules is experimental again
    #29754
* fs:
  * Introduce `opendir()` and `fs.Dir` to iterate through directories
    #29349
* process:
  * Add source-map support to stack traces by using
    `--source-map-support` #29564
* tls:
  * Honor `pauseOnConnect` option
    #29635
  * Add option for private keys for OpenSSL engines
    #28973

PR-URL: TBD
@BridgeAR BridgeAR referenced this pull request Oct 10, 2019
BridgeAR added a commit that referenced this pull request Oct 10, 2019
Notable changes:

* build:
  * Add `--force-context-aware` flag to prevent usage of native node
    addons that aren't context aware
    #29631
* deprecations:
  * Add documentation-only deprecation for `process._tickCallback()`
    #29781
* esm:
  * Using JSON modules is experimental again
    #29754
* fs:
  * Introduce `opendir()` and `fs.Dir` to iterate through directories
    #29349
* process:
  * Add source-map support to stack traces by using
    `--source-map-support` #29564
* tls:
  * Honor `pauseOnConnect` option
    #29635
  * Add option for private keys for OpenSSL engines
    #28973

PR-URL: #29919
BridgeAR added a commit that referenced this pull request Oct 10, 2019
Notable changes:

* build:
  * Add `--force-context-aware` flag to prevent usage of native node
    addons that aren't context aware
    #29631
* deprecations:
  * Add documentation-only deprecation for `process._tickCallback()`
    #29781
* esm:
  * Using JSON modules is experimental again
    #29754
* fs:
  * Introduce `opendir()` and `fs.Dir` to iterate through directories
    #29349
* process:
  * Add source-map support to stack traces by using
    `--source-map-support` #29564
* tls:
  * Honor `pauseOnConnect` option
    #29635
  * Add option for private keys for OpenSSL engines
    #28973

PR-URL: #29919
BridgeAR added a commit that referenced this pull request Oct 11, 2019
Notable changes:

* build:
  * Add `--force-context-aware` flag to prevent usage of native node
    addons that aren't context aware
    #29631
* deprecations:
  * Add documentation-only deprecation for `process._tickCallback()`
    #29781
* esm:
  * Using JSON modules is experimental again
    #29754
* fs:
  * Introduce `opendir()` and `fs.Dir` to iterate through directories
    #29349
* process:
  * Add source-map support to stack traces by using
    `--source-map-support` #29564
* tls:
  * Honor `pauseOnConnect` option
    #29635
  * Add option for private keys for OpenSSL engines
    #28973

PR-URL: #29919
BridgeAR added a commit that referenced this pull request Oct 11, 2019
Notable changes:

* build:
  * Add `--force-context-aware` flag to prevent usage of native node
    addons that aren't context aware
    #29631
* deprecations:
  * Add documentation-only deprecation for `process._tickCallback()`
    #29781
* esm:
  * Using JSON modules is experimental again
    #29754
* fs:
  * Introduce `opendir()` and `fs.Dir` to iterate through directories
    #29349
* process:
  * Add source-map support to stack traces by using
    `--source-map-support` #29564
* tls:
  * Honor `pauseOnConnect` option
    #29635
  * Add option for private keys for OpenSSL engines
    #28973

PR-URL: #29919
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.