mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
herrors: Improve handling of JSON errors
`*json.UnmarshalTypeError` and `*json.SyntaxError` has a byte `Offset`, so use that. This commit also reworks/simplifies the errror line matching logic. This also makes the file reading unbuffered, but that should be fine in this error case. See #5324
This commit is contained in:
@@ -162,18 +162,18 @@ func (t *TemplateAdapter) addFileContext(name string, inerr error) error {
|
||||
|
||||
// Since this can be a composite of multiple template files (single.html + baseof.html etc.)
|
||||
// we potentially need to look in both -- and cannot rely on line number alone.
|
||||
lineMatcher := func(le herrors.FileError, lineNumber int, line string) bool {
|
||||
if le.LineNumber() != lineNumber {
|
||||
lineMatcher := func(m herrors.LineMatcher) bool {
|
||||
if m.FileError.LineNumber() != m.LineNumber {
|
||||
return false
|
||||
}
|
||||
if !hasMaster {
|
||||
return true
|
||||
}
|
||||
|
||||
identifiers := t.extractIdentifiers(le.Error())
|
||||
identifiers := t.extractIdentifiers(m.FileError.Error())
|
||||
|
||||
for _, id := range identifiers {
|
||||
if strings.Contains(line, id) {
|
||||
if strings.Contains(m.Line, id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user