WrapSyntaxError checks whether the given error is a *json.SyntaxError and converts it into a *schema.SyntaxError containing line/col information using the given reader. If the given error is not a *json.SyntaxError it is returned unchanged. Deprecated: WrapSyntaxError is no longer returned by Valid
(r io.Reader, err error)
| 39 | // |
| 40 | // Deprecated: WrapSyntaxError is no longer returned by Validator. |
| 41 | func WrapSyntaxError(r io.Reader, err error) error { |
| 42 | var serr *json.SyntaxError |
| 43 | if errors.As(err, &serr) { |
| 44 | buf := bufio.NewReader(r) |
| 45 | line := 0 |
| 46 | col := 0 |
| 47 | for i := int64(0); i < serr.Offset; i++ { |
| 48 | b, berr := buf.ReadByte() |
| 49 | if berr != nil { |
| 50 | break |
| 51 | } |
| 52 | if b == '\n' { |
| 53 | line++ |
| 54 | col = 1 |
| 55 | } else { |
| 56 | col++ |
| 57 | } |
| 58 | } |
| 59 | return &SyntaxError{serr.Error(), line, col, serr.Offset} |
| 60 | } |
| 61 | |
| 62 | return err |
| 63 | } |