Skip to content

Commit

Permalink
fix potential panic in IsRecoverable
Browse files Browse the repository at this point in the history
The way `unrecoverableError` wraps an error can lead to potential
panics. In `IsRecoverable`, an `unrecoverableError` is passed to
`errors.Is` without an embedded error. This is problematic because any
error type that implements the `Is` interface and expects to be able to
call `Error()` will trigger a panic due to the embedded error being
`nil`.

To fix this, we can implement `Error()` on `unrecoverableError` and
handle the case where the embedded error is nil.
  • Loading branch information
jalaziz committed Nov 14, 2023
1 parent a9809a7 commit 6d7679d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ type unrecoverableError struct {
error
}

func (e unrecoverableError) Error() string {
if e.error == nil {
return "unrecoverable error"
}
return e.error.Error()
}

func (e unrecoverableError) Unwrap() error {
return e.error
}
Expand Down

0 comments on commit 6d7679d

Please sign in to comment.