summaryrefslogtreecommitdiff
path: root/decode.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-27 01:24:02 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-10 21:54:37 -0700
commit49415d88cdd0eed102627369bfdf9de78d0e8bed (patch)
tree0ec8a2d602eb234a37c0d39906e4c645e6b8bac8 /decode.go
parentcf8f8527e968c448995bdcaaad9c4351d3a2ab3f (diff)
tree-wide: Audit panic error messages
These shouldn't happen, but if they do, then let's make it easier to debug.
Diffstat (limited to 'decode.go')
-rw-r--r--decode.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/decode.go b/decode.go
index 976cc6a..1ff8938 100644
--- a/decode.go
+++ b/decode.go
@@ -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))
}
}
}