@@ -110,11 +110,11 @@ func (fe *fileError) UpdateContent(r io.Reader, linematcher LineMatcherFn) FileE
110110
111111 fe .errorContext = ectx
112112
113- if ectx .Position .LineNumber > 0 {
113+ if ectx .Position .LineNumber > 0 && ectx . Position . LineNumber > fe . position . LineNumber {
114114 fe .position .LineNumber = ectx .Position .LineNumber
115115 }
116116
117- if ectx .Position .ColumnNumber > 0 {
117+ if ectx .Position .ColumnNumber > 0 && ectx . Position . ColumnNumber > fe . position . ColumnNumber {
118118 fe .position .ColumnNumber = ectx .Position .ColumnNumber
119119 }
120120
@@ -177,6 +177,7 @@ func NewFileErrorFromName(err error, name string) FileError {
177177 // Filetype is used to determine the Chroma lexer to use.
178178 fileType , pos := extractFileTypePos (err )
179179 pos .Filename = name
180+
180181 if fileType == "" {
181182 _ , fileType = paths .FileAndExtNoDelimiter (filepath .Clean (name ))
182183 }
@@ -234,7 +235,9 @@ func NewFileErrorFromFile(err error, filename string, fs afero.Fs, linematcher L
234235 return NewFileErrorFromName (err , realFilename )
235236 }
236237 defer f .Close ()
237- return NewFileErrorFromName (err , realFilename ).UpdateContent (f , linematcher )
238+ fe := NewFileErrorFromName (err , realFilename )
239+ fe = fe .UpdateContent (f , linematcher )
240+ return fe
238241}
239242
240243func openFile (filename string , fs afero.Fs ) (afero.File , string , error ) {
@@ -321,13 +324,9 @@ func extractFileTypePos(err error) (string, text.Position) {
321324 }
322325
323326 // Look in the error message for the line number.
324- for _ , handle := range lineNumberExtractors {
325- lno , col := handle (err )
326- if lno > 0 {
327- pos .ColumnNumber = col
328- pos .LineNumber = lno
329- break
330- }
327+ if lno , col := commonLineNumberExtractor (err ); lno > 0 {
328+ pos .ColumnNumber = col
329+ pos .LineNumber = lno
331330 }
332331
333332 if fileType == "" && pos .Filename != "" {
0 commit comments