Skip to content

Commit 4e92ad6

Browse files
authored
Merge pull request #1802 from uvw/go-error-wrapping
Support Go 1.13 error unwrapping
2 parents 84360ef + 34549ec commit 4e92ad6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

async_producer.go

+4
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ func (pe ProducerError) Error() string {
267267
return fmt.Sprintf("kafka: Failed to produce message to topic %s: %s", pe.Msg.Topic, pe.Err)
268268
}
269269

270+
func (pe ProducerError) Unwrap() error {
271+
return pe.Err
272+
}
273+
270274
// ProducerErrors is a type that wraps a batch of "ProducerError"s and implements the Error interface.
271275
// It can be returned from the Producer's Close method to avoid the need to manually drain the Errors channel
272276
// when closing a producer.

consumer.go

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func (ce ConsumerError) Error() string {
3535
return fmt.Sprintf("kafka: error while consuming %s/%d: %s", ce.Topic, ce.Partition, ce.Err)
3636
}
3737

38+
func (ce ConsumerError) Unwrap() error {
39+
return ce.Err
40+
}
41+
3842
// ConsumerErrors is a type that wraps a batch of errors and implements the Error interface.
3943
// It can be returned from the PartitionConsumer's Close methods to avoid the need to manually drain errors
4044
// when stopping.

0 commit comments

Comments
 (0)