File tree 1 file changed +26
-16
lines changed
packages/gatsby/src/utils 1 file changed +26
-16
lines changed Original file line number Diff line number Diff line change 1
1
import stackTrace , { StackFrame } from "stack-trace"
2
+ import url from "url"
2
3
import { codeFrameColumns } from "@babel/code-frame"
3
4
import {
4
5
TraceMap ,
@@ -71,23 +72,32 @@ export const getNonGatsbyCodeFrame = ({
71
72
const line = callSite . getLineNumber ( )
72
73
const column = callSite . getColumnNumber ( )
73
74
74
- const code = fs . readFileSync ( fileName , { encoding : `utf-8` } )
75
- return {
76
- fileName,
77
- line,
78
- column,
79
- codeFrame : codeFrameColumns (
80
- code ,
81
- {
82
- start : {
83
- line,
84
- column,
75
+ const normalizedFileName = fileName . startsWith ( `file://` )
76
+ ? url . fileURLToPath ( fileName )
77
+ : fileName
78
+
79
+ try {
80
+ const code = fs . readFileSync ( normalizedFileName , { encoding : `utf-8` } )
81
+ return {
82
+ fileName,
83
+ line,
84
+ column,
85
+ codeFrame : codeFrameColumns (
86
+ code ,
87
+ {
88
+ start : {
89
+ line,
90
+ column,
91
+ } ,
85
92
} ,
86
- } ,
87
- {
88
- highlightCode,
89
- }
90
- ) ,
93
+ {
94
+ highlightCode,
95
+ }
96
+ ) ,
97
+ }
98
+ } catch ( e ) {
99
+ console . error ( `Errored getting code frame: ${ e . stack } ` )
100
+ return null
91
101
}
92
102
}
93
103
You can’t perform that action at this time.
0 commit comments