Skip to content

Commit

Permalink
add better error if crc checksums mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrayford committed Aug 25, 2017
1 parent 0eb6982 commit 749486f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crc32_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sarama

import (
"encoding/binary"
"fmt"
"hash/crc32"
)

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

if crc != binary.BigEndian.Uint32(buf[c.startOffset:]) {
return PacketDecodingError{"CRC didn't match"}
expected := binary.BigEndian.Uint32(buf[c.startOffset:])
if crc != expected {
return PacketDecodingError{fmt.Sprintf("CRC didn't match expected %v got %v", expected, crc)}
}

return nil
Expand Down

0 comments on commit 749486f

Please sign in to comment.