MCPcopy Index your code
hub / github.com/opencontainers/image-spec / WrapSyntaxError

Function WrapSyntaxError

schema/error.go:41–63  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

39//
40// Deprecated: WrapSyntaxError is no longer returned by Validator.
41func 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}

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.95

Tested by

no test coverage detected