Skip to content

Commit

Permalink
Merge pull request #1802 from uvw/go-error-wrapping
Browse files Browse the repository at this point in the history
Support Go 1.13 error unwrapping
  • Loading branch information
bai committed Sep 24, 2020
2 parents 84360ef + 34549ec commit 4e92ad6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions async_producer.go
Expand Up @@ -267,6 +267,10 @@ func (pe ProducerError) Error() string {
return fmt.Sprintf("kafka: Failed to produce message to topic %s: %s", pe.Msg.Topic, pe.Err)
}

func (pe ProducerError) Unwrap() error {
return pe.Err
}

// ProducerErrors is a type that wraps a batch of "ProducerError"s and implements the Error interface.
// It can be returned from the Producer's Close method to avoid the need to manually drain the Errors channel
// when closing a producer.
Expand Down
4 changes: 4 additions & 0 deletions consumer.go
Expand Up @@ -35,6 +35,10 @@ func (ce ConsumerError) Error() string {
return fmt.Sprintf("kafka: error while consuming %s/%d: %s", ce.Topic, ce.Partition, ce.Err)
}

func (ce ConsumerError) Unwrap() error {
return ce.Err
}

// ConsumerErrors is a type that wraps a batch of errors and implements the Error interface.
// It can be returned from the PartitionConsumer's Close methods to avoid the need to manually drain errors
// when stopping.
Expand Down

0 comments on commit 4e92ad6

Please sign in to comment.