-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
errors: display original symbol name #36042
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
Changes from 1 commit
56d7975
f46eb0c
a5f883c
25c45f9
8b4a2b1
e469554
2624239
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
If symbol names array has been populated in source map, include original symbol name in error message. Fixes #35325
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,14 +64,14 @@ const prepareStackTrace = (globalThis, error, trace) => { | |
| const { | ||
| originalLine, | ||
| originalColumn, | ||
| originalSource | ||
| originalSource, | ||
| name | ||
| } = sm.findEntry(t.getLineNumber() - 1, t.getColumnNumber() - 1); | ||
| if (originalSource && originalLine !== undefined && | ||
| originalColumn !== undefined) { | ||
| if (i === 0) { | ||
| firstLine = originalLine + 1; | ||
| firstColumn = originalColumn + 1; | ||
|
|
||
| // Show error in original source context to help user pinpoint it: | ||
| errorSource = getErrorSource( | ||
| sm.payload, | ||
|
|
@@ -81,11 +81,12 @@ const prepareStackTrace = (globalThis, error, trace) => { | |
| ); | ||
| } | ||
| // Show both original and transpiled stack trace information: | ||
| const prefix = name ? `\n -> at ${name}` : '\n ->'; | ||
| const originalSourceNoScheme = | ||
| StringPrototypeStartsWith(originalSource, 'file://') ? | ||
| fileURLToPath(originalSource) : originalSource; | ||
| str += `\n -> ${originalSourceNoScheme}:${originalLine + 1}:` + | ||
| `${originalColumn + 1}`; | ||
| str += `${prefix} (${originalSourceNoScheme}:${originalLine + 1}:` + | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth noting that this puts a Error: an exception
at branch (/Users/bencoe/oss/node-1/test/fixtures/source-map/typescript-throw.js:20:15)
-> (/Users/bencoe/oss/node-1/test/fixtures/source-map/typescript-throw.ts:18:11)Edit: figured while we're calling the feature experimental, it's the time to make these tweaks.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a heads up, this might make it incompatible with the tc39 stacks proposal, if it ever lands - it’ll only specify the union of what browsers do.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ljharb what would you suggest we do to provide appropriate context about the transpiled call site and original call site, in the spirit of the spirit of the tc39 stacks proposal? I'm hoping to make the case for removing the experimental language from
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The challenge is specifying what browsers all already do, without permitting anything beyond that. What do browsers do here on source mapped exception stacks? If the answer is “nothing special”, then that’s probably what node should do too :-/
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
TypeScript and other transpiled flavors or JavaScript have exploded in popularity over the past several years, I'd argue that stack traces just haven't caught up with this need:
I would have originally gone with the approach It would be nice if the stacks proposal gave us enough flexibility that we could insert this extra contextual information into the stack trace, without breaking upstream parser. Couldn't we just consider this to be one line of the stack trace: ☝️ the tabbed in line without an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ljharb let's move this conversation to the TC39 proposal; this PR is just patching a bug, not introducing new behavior to Node.js.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. per our offline discussion, it might be simpler for now to leave
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this land as-is, with the parentheticals discussed here? |
||
| `${originalColumn + 1})`; | ||
| } | ||
| } | ||
| } catch (err) { | ||
|
|
||
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.
nit: consider adding a trailing comma to make future PR diffs cleaner?
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 think this is a style that a separate PR should use linting to enforce, and also apply everywhere. (iow i think it’s a great change, but i don’t think node’s followed it consistently thus far)
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.
Agreed, to be clear I'm +1 landing this with or without the trailing commas.