Skip to content

Commit

Permalink
fix(gatsby): try to get linenumber from compile error (#30615)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Apr 22, 2021
1 parent b3051ae commit 7dd645d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -14,6 +14,12 @@ export function BuildError({ error }) {
const decoded = prettifyStack(error)
const [filePath] = decoded
const file = filePath.content.split(`\n`)[0]
const lineMatch = filePath.content.match(/\((\d+)[^)]+\)/)
let line = 1

if (lineMatch) {
line = lineMatch[1]
}

return (
<Overlay>
Expand All @@ -22,7 +28,10 @@ export function BuildError({ error }) {
<h1 id="gatsby-overlay-labelledby">Failed to compile</h1>
<span>{file}</span>
</div>
<HeaderOpenClose open={() => openInEditor(file, 1)} dismiss={false} />
<HeaderOpenClose
open={() => openInEditor(file, line)}
dismiss={false}
/>
</Header>
<Body>
<h2>Source</h2>
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/fast-refresh-overlay/utils.js
Expand Up @@ -23,7 +23,7 @@ export function prettifyStack(errorInformation) {
}

export function openInEditor(file, lineNumber = 1) {
window.fetch(
fetch(
`/__open-stack-frame-in-editor?fileName=` +
window.encodeURIComponent(file) +
`&lineNumber=` +
Expand Down

0 comments on commit 7dd645d

Please sign in to comment.