From 49415d88cdd0eed102627369bfdf9de78d0e8bed Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 27 Jan 2023 01:24:02 -0700 Subject: tree-wide: Audit panic error messages These shouldn't happen, but if they do, then let's make it easier to debug. --- internal/jsonparse/parse.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'internal') diff --git a/internal/jsonparse/parse.go b/internal/jsonparse/parse.go index 7d97be0..73584d9 100644 --- a/internal/jsonparse/parse.go +++ b/internal/jsonparse/parse.go @@ -401,7 +401,7 @@ func (par *Parser) PushReadBarrier() { // Sanity checking. par.init() if len(par.stack) == 0 { - panic(errors.New("illegal PushReadBarrier call: empty stack")) + panic(errors.New("should not happen: illegal PushReadBarrier call: empty stack")) } curState := par.stack[len(par.stack)-1] switch curState { @@ -415,7 +415,7 @@ func (par *Parser) PushReadBarrier() { RuneTypeNullN: // OK default: - panic(fmt.Errorf("illegal PushReadBarrier call: %q", curState)) + panic(fmt.Errorf("should not happen: illegal PushReadBarrier call: %q", curState)) } // Actually push. par.barriers = append(par.barriers, barrier{ @@ -441,7 +441,7 @@ func (par *Parser) PushReadBarrier() { func (par *Parser) PushWriteBarrier() { par.init() if len(par.stack) == 0 { - panic(errors.New("illegal PushWriteBarrier call: empty stack")) + panic(errors.New("should not happen: illegal PushWriteBarrier call: empty stack")) } switch par.stack[len(par.stack)-1] { case runeTypeAny: @@ -459,14 +459,14 @@ func (par *Parser) PushWriteBarrier() { }) par.stack = []RuneType{runeTypeAny} default: - panic(fmt.Errorf("illegal PushWriteBarrier call: %q", par.stack[len(par.stack)-1])) + panic(fmt.Errorf("should not happen: illegal PushWriteBarrier call: %q", par.stack[len(par.stack)-1])) } } // PopBarrier reverses a call to PushReadBarrier or PushWriteBarrier. func (par *Parser) PopBarrier() { if len(par.barriers) == 0 { - panic(errors.New("illegal PopBarrier call: empty barrier stack")) + panic(errors.New("should not happen: illegal PopBarrier call: empty barrier stack")) } barrier := par.barriers[len(par.barriers)-1] par.barriers = par.barriers[:len(par.barriers)-1] @@ -828,7 +828,7 @@ func (par *Parser) HandleRune(c rune) (RuneType, error) { case RuneTypeNullL1: return par.expectRune(c, 'l', RuneTypeNullL2, "null", true) default: - panic(fmt.Errorf(`invalid stack: "%s"`, par.stackString())) + panic(fmt.Errorf(`should not happen: invalid stack: "%s"`, par.stackString())) } } -- cgit v1.2.3-2-g168b