diff options
Diffstat (limited to 'decode.go')
-rw-r--r-- | decode.go | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -302,12 +302,12 @@ func (dec *Decoder) expectRune(ec rune, et jsonparse.RuneType) { } } -func (dec *Decoder) expectRuneType(ec rune, et jsonparse.RuneType, gt reflect.Type) { +func (dec *Decoder) expectRuneType(ec rune, et jsonparse.RuneType, gt reflect.Type) *DecodeError { ac, at := dec.readRune() if ac != ec || at != et { - err := dec.newTypeError(at.JSONType(), gt, nil) - panic(decodeError(*err)) + return dec.newTypeError(at.JSONType(), gt, nil) } + return nil } type decRuneScanner struct { @@ -990,7 +990,9 @@ func DecodeObject(r io.RuneScanner, decodeKey, decodeVal func(io.RuneScanner) er } func (dec *Decoder) decodeObject(gTyp reflect.Type, decodeKey, decodeVal func() *DecodeError) *DecodeError { - dec.expectRuneType('{', jsonparse.RuneTypeObjectBeg, gTyp) + if err := dec.expectRuneType('{', jsonparse.RuneTypeObjectBeg, gTyp); err != nil { + return err + } _, t := dec.readRune() switch t { case jsonparse.RuneTypeObjectEnd: @@ -1069,7 +1071,9 @@ func DecodeArray(r io.RuneScanner, decodeMember func(r io.RuneScanner) error) (e } func (dec *Decoder) decodeArray(gTyp reflect.Type, decodeMember func() *DecodeError) *DecodeError { - dec.expectRuneType('[', jsonparse.RuneTypeArrayBeg, gTyp) + if err := dec.expectRuneType('[', jsonparse.RuneTypeArrayBeg, gTyp); err != nil { + return err + } _, t := dec.readRune() switch t { case jsonparse.RuneTypeArrayEnd: @@ -1093,7 +1097,9 @@ func (dec *Decoder) decodeArray(gTyp reflect.Type, decodeMember func() *DecodeEr } func (dec *Decoder) decodeString(gTyp reflect.Type, out fastio.RuneWriter) *DecodeError { - dec.expectRuneType('"', jsonparse.RuneTypeStringBeg, gTyp) + if err := dec.expectRuneType('"', jsonparse.RuneTypeStringBeg, gTyp); err != nil { + return err + } var uhex [4]byte for { c, t := dec.readRune() |