mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-13 09:06:41 +00:00
core: Show JSON error offsets where possible (#7437)
This commit is contained in:
parent
e40bd019ff
commit
d269405eab
4 changed files with 18 additions and 4 deletions
|
|
@ -342,7 +342,11 @@ func ParseStructTag(tag string) (map[string]string, error) {
|
|||
func StrictUnmarshalJSON(data []byte, v any) error {
|
||||
dec := json.NewDecoder(bytes.NewReader(data))
|
||||
dec.DisallowUnknownFields()
|
||||
return dec.Decode(v)
|
||||
err := dec.Decode(v)
|
||||
if jsonErr, ok := err.(*json.SyntaxError); ok {
|
||||
return fmt.Errorf("%w, at offset %d", jsonErr, jsonErr.Offset)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
var JSONRawMessageType = reflect.TypeFor[json.RawMessage]()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue