From b0ab43e5d8944541fb4362b05b1eea1b97476354 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 24 Mar 2020 09:21:49 +0100 Subject: [PATCH] Add more details to ring buffer panics --- ring.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ring.go b/ring.go index 9833d98..9bb23ac 100644 --- a/ring.go +++ b/ring.go @@ -1,6 +1,7 @@ package soju import ( + "fmt" "sync" "gopkg.in/irc.v3" @@ -86,7 +87,7 @@ type RingConsumer struct { // diff returns the number of pending messages. It assumes the Ring is locked. func (rc *RingConsumer) diff() uint64 { 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 } @@ -112,7 +113,7 @@ func (rc *RingConsumer) Peek() *irc.Message { i := int(rc.cur % rc.ring.cap) msg := rc.ring.buffer[i] 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 }