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:
Bjørn Erik Pedersen
2018-10-23 08:54:10 +02:00
parent ed7b3e2619
commit f669ef6bec
10 changed files with 228 additions and 119 deletions

View File

@@ -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
}
}