diff --git a/message.go b/message.go index 2c877390..c161e3cb 100644 --- a/message.go +++ b/message.go @@ -736,7 +736,7 @@ func (d *Decoder) Decode() (*Message, error) { } maxSeg := SegmentID(binary.LittleEndian.Uint32(d.wordbuf[:])) if maxSeg > maxStreamSegments { - return nil, errors.New("decode: too many segments to decode") + return nil, errSegIDTooLarge(maxSeg) } // Read the rest of the header if more than one segment. @@ -804,6 +804,14 @@ func (d *Decoder) Decode() (*Message, error) { return &d.msg, nil } +type errSegIDTooLarge SegmentID + +func (err errSegIDTooLarge) Error() string { + id := str.Utod(err) + max := str.Itod(maxStreamSegments) + return "decode: segment id" + id + "exceeds max segment count (max=" + max + ")" +} + func resizeSlice(b []byte, size int) []byte { if cap(b) < size { return make([]byte, size)