Skip to content

Commit

Permalink
update isTimeout and isTemporary to properly unwrap errors (segmentio…
Browse files Browse the repository at this point in the history
…#616)

* update isTimeout and isTemporary to properly unwrap errors

* use interface instead
  • Loading branch information
ianthpun authored Mar 26, 2021
1 parent 6345479 commit 9cb6db9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions error.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kafka

import (
"errors"
"fmt"
"io"
)
Expand Down Expand Up @@ -491,17 +492,19 @@ func (e Error) Description() string {
}

func isTimeout(err error) bool {
e, ok := err.(interface {
Timeout() bool
})
return ok && e.Timeout()
var timeoutError interface{ Timeout() bool }
if errors.As(err, &timeoutError) {
return timeoutError.Timeout()
}
return false
}

func isTemporary(err error) bool {
e, ok := err.(interface {
Temporary() bool
})
return ok && e.Temporary()
var tempError interface{ Temporary() bool }
if errors.As(err, &tempError) {
return tempError.Temporary()
}
return false
}

func silentEOF(err error) error {
Expand Down

0 comments on commit 9cb6db9

Please sign in to comment.