From cf5894e0927e66175468e7622712d2a4c6df0964 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 14:45:33 -0600 Subject: [PATCH] Use std errors instead of golang.org/x/xerrors New error functionality was introduced in Go 1.13. pgconn only officially supports 1.15+. Transitional xerrors package can now be removed. --- auth_scram.go | 6 +++--- config.go | 8 ++++---- errors.go | 3 +-- go.mod | 1 - pgconn.go | 5 +++-- pgconn_test.go | 6 ++---- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/auth_scram.go b/auth_scram.go index 665fc2c2..6a143fcd 100644 --- a/auth_scram.go +++ b/auth_scram.go @@ -18,13 +18,13 @@ import ( "crypto/rand" "crypto/sha256" "encoding/base64" + "errors" "fmt" "strconv" "github.com/jackc/pgproto3/v2" "golang.org/x/crypto/pbkdf2" "golang.org/x/text/secure/precis" - errors "golang.org/x/xerrors" ) const clientNonceLen = 18 @@ -192,12 +192,12 @@ func (sc *scramClient) recvServerFirstMessage(serverFirstMessage []byte) error { var err error sc.salt, err = base64.StdEncoding.DecodeString(string(saltStr)) if err != nil { - return errors.Errorf("invalid SCRAM salt received from server: %w", err) + return fmt.Errorf("invalid SCRAM salt received from server: %w", err) } sc.iterations, err = strconv.Atoi(string(iterationsStr)) if err != nil || sc.iterations <= 0 { - return errors.Errorf("invalid SCRAM iteration count received from server: %w", err) + return fmt.Errorf("invalid SCRAM iteration count received from server: %w", err) } if !bytes.HasPrefix(sc.clientAndServerNonce, sc.clientNonce) { diff --git a/config.go b/config.go index 38e94f26..c162d3c3 100644 --- a/config.go +++ b/config.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "crypto/x509" + "errors" "fmt" "io" "io/ioutil" @@ -20,7 +21,6 @@ import ( "github.com/jackc/pgpassfile" "github.com/jackc/pgproto3/v2" "github.com/jackc/pgservicefile" - errors "golang.org/x/xerrors" ) type AfterConnectFunc func(ctx context.Context, pgconn *PgConn) error @@ -409,7 +409,7 @@ func parseURLSettings(connString string) (map[string]string, error) { } h, p, err := net.SplitHostPort(host) if err != nil { - return nil, errors.Errorf("failed to split host:port in '%s', err: %w", host, err) + return nil, fmt.Errorf("failed to split host:port in '%s', err: %w", host, err) } hosts = append(hosts, h) ports = append(ports, p) @@ -617,7 +617,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) { caPath := sslrootcert caCert, err := ioutil.ReadFile(caPath) if err != nil { - return nil, errors.Errorf("unable to read CA file: %w", err) + return nil, fmt.Errorf("unable to read CA file: %w", err) } if !caCertPool.AppendCertsFromPEM(caCert) { @@ -635,7 +635,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) { if sslcert != "" && sslkey != "" { cert, err := tls.LoadX509KeyPair(sslcert, sslkey) if err != nil { - return nil, errors.Errorf("unable to read cert: %w", err) + return nil, fmt.Errorf("unable to read cert: %w", err) } tlsConfig.Certificates = []tls.Certificate{cert} diff --git a/errors.go b/errors.go index b37b1d97..77adfcf0 100644 --- a/errors.go +++ b/errors.go @@ -2,13 +2,12 @@ package pgconn import ( "context" + "errors" "fmt" "net" "net/url" "regexp" "strings" - - errors "golang.org/x/xerrors" ) // SafeToRetry checks if the err is guaranteed to have occurred before sending any data to the server. diff --git a/go.mod b/go.mod index 7e578765..2dc0cd4d 100644 --- a/go.mod +++ b/go.mod @@ -12,5 +12,4 @@ require ( github.com/stretchr/testify v1.5.1 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/text v0.3.3 - golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 ) diff --git a/pgconn.go b/pgconn.go index 0c1717ff..20233e57 100644 --- a/pgconn.go +++ b/pgconn.go @@ -6,6 +6,8 @@ import ( "crypto/tls" "encoding/binary" "encoding/hex" + "errors" + "fmt" "io" "math" "net" @@ -16,7 +18,6 @@ import ( "github.com/jackc/pgconn/internal/ctxwatch" "github.com/jackc/pgio" "github.com/jackc/pgproto3/v2" - errors "golang.org/x/xerrors" ) const ( @@ -1043,7 +1044,7 @@ func (pgConn *PgConn) execExtendedPrefix(ctx context.Context, paramValues [][]by } if len(paramValues) > math.MaxUint16 { - result.concludeCommand(nil, errors.Errorf("extended protocol limited to %v parameters", math.MaxUint16)) + result.concludeCommand(nil, fmt.Errorf("extended protocol limited to %v parameters", math.MaxUint16)) result.closed = true pgConn.unlock() return result diff --git a/pgconn_test.go b/pgconn_test.go index 87edefc2..7ceda791 100644 --- a/pgconn_test.go +++ b/pgconn_test.go @@ -5,6 +5,7 @@ import ( "compress/gzip" "context" "crypto/tls" + "errors" "fmt" "io" "io/ioutil" @@ -17,12 +18,9 @@ import ( "testing" "time" - "github.com/jackc/pgmock" - "github.com/jackc/pgconn" + "github.com/jackc/pgmock" "github.com/jackc/pgproto3/v2" - errors "golang.org/x/xerrors" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" )