Skip to content

Commit 6d7679d

Browse files
committed
fix potential panic in IsRecoverable
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.
1 parent a9809a7 commit 6d7679d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

retry.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ type unrecoverableError struct {
302302
error
303303
}
304304

305+
func (e unrecoverableError) Error() string {
306+
if e.error == nil {
307+
return "unrecoverable error"
308+
}
309+
return e.error.Error()
310+
}
311+
305312
func (e unrecoverableError) Unwrap() error {
306313
return e.error
307314
}

0 commit comments

Comments
 (0)