From 579a320c1c81636726a1fb12fa612da7746effbc Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 9 May 2024 17:59:16 -0500 Subject: [PATCH] pgconn.SafeToRetry checks for wrapped errors Use errors.As instead of type assertion. Port 4e2e7a040579c1999c0766642d836eb28c6e2018 to v5 Credit to tjasko --- pgconn/errors.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pgconn/errors.go b/pgconn/errors.go index 6790b9b6a..ecc9d332c 100644 --- a/pgconn/errors.go +++ b/pgconn/errors.go @@ -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 }