Add more details to ring buffer panics

This commit is contained in:
Simon Ser 2020-03-24 09:21:49 +01:00
parent 015281ed35
commit b0ab43e5d8
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -1,6 +1,7 @@
package soju package soju
import ( import (
"fmt"
"sync" "sync"
"gopkg.in/irc.v3" "gopkg.in/irc.v3"
@ -86,7 +87,7 @@ type RingConsumer struct {
// diff returns the number of pending messages. It assumes the Ring is locked. // diff returns the number of pending messages. It assumes the Ring is locked.
func (rc *RingConsumer) diff() uint64 { func (rc *RingConsumer) diff() uint64 {
if rc.cur > rc.ring.cur { if rc.cur > rc.ring.cur {
panic("soju: consumer cursor greater than producer cursor") panic(fmt.Sprintf("soju: consumer cursor (%v) greater than producer cursor (%v)", rc.cur, rc.ring.cur))
} }
return rc.ring.cur - rc.cur return rc.ring.cur - rc.cur
} }
@ -112,7 +113,7 @@ func (rc *RingConsumer) Peek() *irc.Message {
i := int(rc.cur % rc.ring.cap) i := int(rc.cur % rc.ring.cap)
msg := rc.ring.buffer[i] msg := rc.ring.buffer[i]
if msg == nil { if msg == nil {
panic("soju: unexpected nil ring buffer entry") panic(fmt.Sprintf("soju: unexpected nil ring buffer entry at index %v", i))
} }
return msg return msg
} }