File tree Expand file tree Collapse file tree 2 files changed +10
-25
lines changed Expand file tree Collapse file tree 2 files changed +10
-25
lines changed Original file line number Diff line number Diff line change @@ -16,23 +16,6 @@ package crdb
1616
1717import "fmt"
1818
19- // errorCause returns the original cause of the error, if possible. An
20- // error has a proximate cause if it's type is compatible with Go's
21- // errors.Unwrap() or pkg/errors' Cause(); the original cause is the
22- // end of the causal chain.
23- func errorCause (err error ) error {
24- for err != nil {
25- if c , ok := err .(interface { Cause () error }); ok {
26- err = c .Cause ()
27- } else if c , ok := err .(interface { Unwrap () error }); ok {
28- err = c .Unwrap ()
29- } else {
30- break
31- }
32- }
33- return err
34- }
35-
3619type txError struct {
3720 cause error
3821}
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package crdb
1919import (
2020 "context"
2121 "database/sql"
22+ "errors"
2223
2324 "github.com/lib/pq"
2425)
@@ -193,16 +194,17 @@ func errIsRetryable(err error) bool {
193194}
194195
195196func errCode (err error ) string {
196- switch t := errorCause (err ).(type ) {
197- case * pq.Error :
198- return string (t .Code )
199-
200- case errWithSQLState :
201- return t .SQLState ()
197+ var pqe * pq.Error
198+ if errors .As (err , & pqe ) {
199+ return string (pqe .Code )
200+ }
202201
203- default :
204- return ""
202+ var sqlErr errWithSQLState
203+ if errors .As (err , & sqlErr ) {
204+ return sqlErr .SQLState ()
205205 }
206+
207+ return ""
206208}
207209
208210// errWithSQLState is implemented by pgx (pgconn.PgError).
You can’t perform that action at this time.
0 commit comments