-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Improved stacktraces (minor) #4156
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0642b42
Handle production errors correctly
timneutkens cf590ca
Improved source map support
timneutkens b0a2391
Make react-hot-loader hold state again
timneutkens 6dbfb7d
Remove console.log
timneutkens 966fe31
Load modules on demand
timneutkens ac83b26
Catch errors in rewriteErrorTrace
timneutkens 9695c6d
Update comment
timneutkens 8b7d407
Update comment
timneutkens 45a7b52
Remove source-map-support
timneutkens 8b9271e
Load modules in next-dev
timneutkens 2d6aa5b
Make sure error logged has sourcemaps too
timneutkens f6b8f93
Add tests for production runtime errors
timneutkens 6bef341
Add tests for development runtime errors. Fix issue with client side …
timneutkens c01c1a3
Move functionality back to renderError now that error handling is con…
timneutkens e314208
Rename to applySourcemaps
timneutkens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @flow | ||
import fetch from 'unfetch' | ||
const filenameRE = /\(([^)]+\.js):(\d+):(\d+)\)$/ | ||
|
||
export async function applySourcemaps (e: any): Promise<void> { | ||
if (!e || typeof e.stack !== 'string' || e.sourceMapsApplied) { | ||
return | ||
} | ||
|
||
const lines = e.stack.split('\n') | ||
|
||
const result = await Promise.all(lines.map((line) => { | ||
return rewriteTraceLine(line) | ||
})) | ||
|
||
e.stack = result.join('\n') | ||
// This is to make sure we don't apply the sourcemaps twice on the same object | ||
e.sourceMapsApplied = true | ||
} | ||
|
||
async function rewriteTraceLine (trace: string): Promise<string> { | ||
const m = trace.match(filenameRE) | ||
if (m == null) { | ||
return trace | ||
} | ||
|
||
const filePath = m[1] | ||
if (filePath.match(/node_modules/)) { | ||
return trace | ||
} | ||
|
||
const mapPath = `${filePath}.map` | ||
|
||
const res = await fetch(mapPath) | ||
if (res.status !== 200) { | ||
return trace | ||
} | ||
|
||
const mapContents = await res.json() | ||
const {SourceMapConsumer} = require('source-map') | ||
const map = new SourceMapConsumer(mapContents) | ||
const originalPosition = map.originalPositionFor({ | ||
line: Number(m[2]), | ||
column: Number(m[3]) | ||
}) | ||
|
||
if (originalPosition.source != null) { | ||
const { source, line, column } = originalPosition | ||
const mappedPosition = `(${source.replace(/^webpack:\/\/\//, '')}:${String(line)}:${String(column)})` | ||
return trace.replace(filenameRE, mappedPosition) | ||
} | ||
|
||
return trace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 you can remove the empty fragment here and just
return children
? or is there a clever reason as to why wrap it in a fragment?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.
Just didn't want to change behavior from what it was before.
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.
Sounds good 👍