Skip to content

Commit f5ef216

Browse files
committed
add better error if crc checksums mismatch
1 parent 920e2d0 commit f5ef216

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crc32_field.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sarama
22

33
import (
44
"encoding/binary"
5+
"fmt"
56
"hash/crc32"
67
)
78

@@ -27,8 +28,9 @@ func (c *crc32Field) run(curOffset int, buf []byte) error {
2728
func (c *crc32Field) check(curOffset int, buf []byte) error {
2829
crc := crc32.ChecksumIEEE(buf[c.startOffset+4 : curOffset])
2930

30-
if crc != binary.BigEndian.Uint32(buf[c.startOffset:]) {
31-
return PacketDecodingError{"CRC didn't match"}
31+
expected := binary.BigEndian.Uint32(buf[c.startOffset:])
32+
if crc != expected {
33+
return PacketDecodingError{fmt.Sprintf("CRC didn't match expected %#x got %#x", expected, crc)}
3234
}
3335

3436
return nil

0 commit comments

Comments
 (0)