Skip to content

Commit

Permalink
Merge pull request #800 from zhsj/remove-go4
Browse files Browse the repository at this point in the history
Remove go4.org dependency
  • Loading branch information
vbatts authored Jul 9, 2021
2 parents 083f635 + 78c42f4 commit 93e69bc
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions schema/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
package schema

import (
"bufio"
"encoding/json"
"io"

"go4.org/errorutil"
)

// A SyntaxError is a description of a JSON syntax error
Expand All @@ -36,7 +35,21 @@ func (e *SyntaxError) Error() string { return e.msg }
// If the given error is not a *json.SyntaxError it is returned unchanged.
func WrapSyntaxError(r io.Reader, err error) error {
if serr, ok := err.(*json.SyntaxError); ok {
line, col, _ := errorutil.HighlightBytePosition(r, serr.Offset)
buf := bufio.NewReader(r)
line := 0
col := 0
for i := int64(0); i < serr.Offset; i++ {
b, berr := buf.ReadByte()
if berr != nil {
break
}
if b == '\n' {
line++
col = 1
} else {
col++
}
}
return &SyntaxError{serr.Error(), line, col, serr.Offset}
}

Expand Down

0 comments on commit 93e69bc

Please sign in to comment.