@@ -206,7 +206,7 @@ func NewConnWith(conn net.Conn, config ConnConfig) *Conn {
206
206
func (c * Conn ) negotiateVersion (key apiKey , sortedSupportedVersions ... apiVersion ) (apiVersion , error ) {
207
207
v , err := c .loadVersions ()
208
208
if err != nil {
209
- return - 1 , err
209
+ return - 1 , fmt . Errorf ( "failed to determine available versions: %w" , err )
210
210
}
211
211
a := v .negotiate (key , sortedSupportedVersions ... )
212
212
if a < 0 {
@@ -331,10 +331,10 @@ func (c *Conn) findCoordinator(request findCoordinatorRequestV0) (findCoordinato
331
331
},
332
332
)
333
333
if err != nil {
334
- return findCoordinatorResponseV0 {}, err
334
+ return findCoordinatorResponseV0 {}, fmt . Errorf ( "failed to find coordinator: %w" , err )
335
335
}
336
336
if response .ErrorCode != 0 {
337
- return findCoordinatorResponseV0 {}, Error (response .ErrorCode )
337
+ return findCoordinatorResponseV0 {}, makeError (response .ErrorCode , "failed to find coordinator" )
338
338
}
339
339
340
340
return response , nil
@@ -357,10 +357,10 @@ func (c *Conn) heartbeat(request heartbeatRequestV0) (heartbeatResponseV0, error
357
357
},
358
358
)
359
359
if err != nil {
360
- return heartbeatResponseV0 {}, err
360
+ return heartbeatResponseV0 {}, fmt . Errorf ( "failed to send heartbeat: %w" , err )
361
361
}
362
362
if response .ErrorCode != 0 {
363
- return heartbeatResponseV0 {}, Error (response .ErrorCode )
363
+ return heartbeatResponseV0 {}, makeError (response .ErrorCode , "failed to send heartbeat" )
364
364
}
365
365
366
366
return response , nil
@@ -383,10 +383,10 @@ func (c *Conn) joinGroup(request joinGroupRequestV1) (joinGroupResponseV1, error
383
383
},
384
384
)
385
385
if err != nil {
386
- return joinGroupResponseV1 {}, err
386
+ return joinGroupResponseV1 {}, fmt . Errorf ( "failed to join consumer group: %w" , err )
387
387
}
388
388
if response .ErrorCode != 0 {
389
- return joinGroupResponseV1 {}, Error (response .ErrorCode )
389
+ return joinGroupResponseV1 {}, makeError (response .ErrorCode , "failed to join consumer group" )
390
390
}
391
391
392
392
return response , nil
@@ -409,10 +409,10 @@ func (c *Conn) leaveGroup(request leaveGroupRequestV0) (leaveGroupResponseV0, er
409
409
},
410
410
)
411
411
if err != nil {
412
- return leaveGroupResponseV0 {}, err
412
+ return leaveGroupResponseV0 {}, fmt . Errorf ( "failed to leave consumer group: %w" , err )
413
413
}
414
414
if response .ErrorCode != 0 {
415
- return leaveGroupResponseV0 {}, Error (response .ErrorCode )
415
+ return leaveGroupResponseV0 {}, makeError (response .ErrorCode , "failed to leave consumer group" )
416
416
}
417
417
418
418
return response , nil
@@ -435,10 +435,10 @@ func (c *Conn) listGroups(request listGroupsRequestV1) (listGroupsResponseV1, er
435
435
},
436
436
)
437
437
if err != nil {
438
- return listGroupsResponseV1 {}, err
438
+ return listGroupsResponseV1 {}, fmt . Errorf ( "failed to list consumer groups: %w" , err )
439
439
}
440
440
if response .ErrorCode != 0 {
441
- return listGroupsResponseV1 {}, Error (response .ErrorCode )
441
+ return listGroupsResponseV1 {}, makeError (response .ErrorCode , "failed to list consumer groups" )
442
442
}
443
443
444
444
return response , nil
@@ -461,12 +461,12 @@ func (c *Conn) offsetCommit(request offsetCommitRequestV2) (offsetCommitResponse
461
461
},
462
462
)
463
463
if err != nil {
464
- return offsetCommitResponseV2 {}, err
464
+ return offsetCommitResponseV2 {}, fmt . Errorf ( "failed to commit offsets: %w" , err )
465
465
}
466
466
for _ , r := range response .Responses {
467
467
for _ , pr := range r .PartitionResponses {
468
468
if pr .ErrorCode != 0 {
469
- return offsetCommitResponseV2 {}, Error (pr .ErrorCode )
469
+ return offsetCommitResponseV2 {}, makeError (pr .ErrorCode , "failed to commit offsets" )
470
470
}
471
471
}
472
472
}
@@ -492,12 +492,12 @@ func (c *Conn) offsetFetch(request offsetFetchRequestV1) (offsetFetchResponseV1,
492
492
},
493
493
)
494
494
if err != nil {
495
- return offsetFetchResponseV1 {}, err
495
+ return offsetFetchResponseV1 {}, fmt . Errorf ( "failed to fetch offsets: %w" , err )
496
496
}
497
497
for _ , r := range response .Responses {
498
498
for _ , pr := range r .PartitionResponses {
499
499
if pr .ErrorCode != 0 {
500
- return offsetFetchResponseV1 {}, Error (pr .ErrorCode )
500
+ return offsetFetchResponseV1 {}, makeError (pr .ErrorCode , "failed to fetch offsets" )
501
501
}
502
502
}
503
503
}
@@ -522,10 +522,10 @@ func (c *Conn) syncGroup(request syncGroupRequestV0) (syncGroupResponseV0, error
522
522
},
523
523
)
524
524
if err != nil {
525
- return syncGroupResponseV0 {}, err
525
+ return syncGroupResponseV0 {}, fmt . Errorf ( "failed to finish joining consumer group: %w" , err )
526
526
}
527
527
if response .ErrorCode != 0 {
528
- return syncGroupResponseV0 {}, Error (response .ErrorCode )
528
+ return syncGroupResponseV0 {}, makeError (response .ErrorCode , "failed to finish joining consumer group" )
529
529
}
530
530
531
531
return response , nil
@@ -666,7 +666,7 @@ func (c *Conn) Seek(offset int64, whence int) (int64, error) {
666
666
667
667
first , last , err := c .ReadOffsets ()
668
668
if err != nil {
669
- return 0 , err
669
+ return 0 , fmt . Errorf ( "failed to read offsets: %w" , err )
670
670
}
671
671
672
672
switch whence {
@@ -757,20 +757,20 @@ func (c *Conn) ReadBatchWith(cfg ReadBatchConfig) *Batch {
757
757
var maxFetch = int (c .fetchMaxBytes )
758
758
759
759
if cfg .MinBytes < 0 || cfg .MinBytes > maxFetch {
760
- return & Batch {err : fmt .Errorf ("kafka.(*Conn).ReadBatch: minBytes of %d out of [1,%d] bounds" , cfg .MinBytes , maxFetch )}
760
+ return & Batch {err : fmt .Errorf ("minBytes of %d out of [1,%d] bounds" , cfg .MinBytes , maxFetch )}
761
761
}
762
762
if cfg .MaxBytes < 0 || cfg .MaxBytes > maxFetch {
763
- return & Batch {err : fmt .Errorf ("kafka.(*Conn).ReadBatch: maxBytes of %d out of [1,%d] bounds" , cfg .MaxBytes , maxFetch )}
763
+ return & Batch {err : fmt .Errorf ("maxBytes of %d out of [1,%d] bounds" , cfg .MaxBytes , maxFetch )}
764
764
}
765
765
if cfg .MinBytes > cfg .MaxBytes {
766
- return & Batch {err : fmt .Errorf ("kafka.(*Conn).ReadBatch: minBytes (%d) > maxBytes (%d)" , cfg .MinBytes , cfg .MaxBytes )}
766
+ return & Batch {err : fmt .Errorf ("minBytes (%d) > maxBytes (%d)" , cfg .MinBytes , cfg .MaxBytes )}
767
767
}
768
768
769
769
offset , whence := c .Offset ()
770
770
771
771
offset , err := c .Seek (offset , whence | SeekDontCheck )
772
772
if err != nil {
773
- return & Batch {err : dontExpectEOF (err )}
773
+ return & Batch {err : fmt . Errorf ( "failed to seek to offset %d (whence %d): %w" , offset , whence , dontExpectEOF (err ) )}
774
774
}
775
775
776
776
fetchVersion , err := c .negotiateVersion (fetch , v2 , v5 , v10 )
@@ -833,12 +833,12 @@ func (c *Conn) ReadBatchWith(cfg ReadBatchConfig) *Batch {
833
833
}
834
834
})
835
835
if err != nil {
836
- return & Batch {err : dontExpectEOF (err )}
836
+ return & Batch {err : fmt . Errorf ( "failed to write fetch request (version %d): %w" , fetchVersion , dontExpectEOF (err ) )}
837
837
}
838
838
839
839
_ , size , lock , err := c .waitResponse (& c .rdeadline , id )
840
840
if err != nil {
841
- return & Batch {err : dontExpectEOF (err )}
841
+ return & Batch {err : fmt . Errorf ( "request %d failed to give response: %w" , id , dontExpectEOF (err ) )}
842
842
}
843
843
844
844
var throttle int32
@@ -854,7 +854,7 @@ func (c *Conn) ReadBatchWith(cfg ReadBatchConfig) *Batch {
854
854
throttle , highWaterMark , remain , err = readFetchResponseHeaderV2 (& c .rbuf , size )
855
855
}
856
856
if errors .Is (err , errShortRead ) {
857
- err = checkTimeoutErr (adjustedDeadline )
857
+ err = fmt . Errorf ( "failed to fetch response header (version %d): %w" , fetchVersion , checkTimeoutErr (adjustedDeadline ) )
858
858
}
859
859
860
860
var msgs * messageSetReader
@@ -863,11 +863,11 @@ func (c *Conn) ReadBatchWith(cfg ReadBatchConfig) *Batch {
863
863
msgs = & messageSetReader {empty : true }
864
864
} else {
865
865
msgs , err = newMessageSetReader (& c .rbuf , remain )
866
+ if errors .Is (err , errShortRead ) {
867
+ err = fmt .Errorf ("failed to initialize a reader for set of %d messages: %w" , remain , checkTimeoutErr (adjustedDeadline ))
868
+ }
866
869
}
867
870
}
868
- if errors .Is (err , errShortRead ) {
869
- err = checkTimeoutErr (adjustedDeadline )
870
- }
871
871
return & Batch {
872
872
conn : c ,
873
873
msgs : msgs ,
0 commit comments