diff options
Diffstat (limited to 'decode.go')
-rw-r--r-- | decode.go | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -209,7 +209,7 @@ func (dec *Decoder) DecodeThenEOF(ptr any) (err error) { } c, s, t, _ := dec.io.ReadRuneType() if t != jsonparse.RuneTypeEOF { - panic("should not happen") + panic(fmt.Errorf("should not happen: .ReadRuneType returned non-EOF after decode without .Reset being called: %v", t)) } if s > 0 { return &DecodeError{ @@ -283,7 +283,7 @@ func (dec *Decoder) unreadRune() { if err := dec.io.UnreadRune(); err != nil { // .UnreadRune() must succeed if the previous call was // .ReadRune(), which it always is for this code. - panic("should not happen") + panic(fmt.Errorf("should not happen: UnreadRune: %w", err)) } } @@ -302,7 +302,7 @@ func (dec *Decoder) expectRune(ec rune, et jsonparse.RuneType) *DecodeError { return err } if ac != ec || at != et { - panic("should not happen") + panic(fmt.Errorf("should not happen: expected %q/%v but got %q/%v", ec, et, ac, at)) } return nil } @@ -964,7 +964,7 @@ func (dec *Decoder) decodeAny() (any, *DecodeError) { case jsonparse.RuneTypeNullN: return nil, dec.decodeNull() default: - panic("should not happen") + panic(fmt.Errorf("should not happen: unexpected runeType at beginning of value: %v", t)) } } @@ -1061,10 +1061,10 @@ func (dec *Decoder) decodeObject(gTyp reflect.Type, decodeKey, decodeVal func() case jsonparse.RuneTypeObjectEnd: return nil default: - panic("should not happen") + panic(fmt.Errorf("should not happen: unexpected runeType after k/v pair in object: %v", t)) } default: - panic("should not happen") + panic(fmt.Errorf("should not happen: unexpected runeType after opening '{' of object: %v", t)) } } @@ -1136,7 +1136,7 @@ func (dec *Decoder) decodeArray(gTyp reflect.Type, decodeMember func() *DecodeEr case jsonparse.RuneTypeArrayEnd: return nil default: - panic("should not happen") + panic(fmt.Errorf("should not happen: unexpected runeType after array item: %v", t)) } } } @@ -1175,7 +1175,7 @@ func (dec *Decoder) decodeString(gTyp reflect.Type, out fastio.RuneWriter) *Deco case 't': _, _ = out.WriteRune('\t') default: - panic("should not happen") + panic(fmt.Errorf("should not happen: unexpected rune after backslash: %q", c)) } case jsonparse.RuneTypeStringEscUA: uhex[0], _ = jsonparse.HexToInt(c) @@ -1253,7 +1253,7 @@ func (dec *Decoder) decodeString(gTyp reflect.Type, out fastio.RuneWriter) *Deco case jsonparse.RuneTypeStringEnd: return nil default: - panic("should not happen") + panic(fmt.Errorf("should not happen: unexpected runeType in string: %v", t)) } } } |