Skip to content

Commit

Permalink
pgconn.SafeToRetry checks for wrapped errors
Browse files Browse the repository at this point in the history
Use errors.As instead of type assertion.

Port 4e2e7a040579c1999c0766642d836eb28c6e2018 to v5

Credit to tjasko
  • Loading branch information
jackc committed May 9, 2024
1 parent 01d649b commit 579a320
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pgconn/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

// SafeToRetry checks if the err is guaranteed to have occurred before sending any data to the server.
func SafeToRetry(err error) bool {
if e, ok := err.(interface{ SafeToRetry() bool }); ok {
return e.SafeToRetry()
var retryableErr interface{ SafeToRetry() bool }
if errors.As(err, &retryableErr) {
return retryableErr.SafeToRetry()
}
return false
}
Expand Down

0 comments on commit 579a320

Please sign in to comment.