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.
This commit is contained in:
Jack Christensen 2021-03-06 14:45:33 -06:00
parent 3b0400a0d4
commit cf5894e092
6 changed files with 13 additions and 16 deletions

View File

@ -18,13 +18,13 @@ import (
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"github.com/jackc/pgproto3/v2" "github.com/jackc/pgproto3/v2"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"golang.org/x/text/secure/precis" "golang.org/x/text/secure/precis"
errors "golang.org/x/xerrors"
) )
const clientNonceLen = 18 const clientNonceLen = 18
@ -192,12 +192,12 @@ func (sc *scramClient) recvServerFirstMessage(serverFirstMessage []byte) error {
var err error var err error
sc.salt, err = base64.StdEncoding.DecodeString(string(saltStr)) sc.salt, err = base64.StdEncoding.DecodeString(string(saltStr))
if err != nil { 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)) sc.iterations, err = strconv.Atoi(string(iterationsStr))
if err != nil || sc.iterations <= 0 { 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) { if !bytes.HasPrefix(sc.clientAndServerNonce, sc.clientNonce) {

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -20,7 +21,6 @@ import (
"github.com/jackc/pgpassfile" "github.com/jackc/pgpassfile"
"github.com/jackc/pgproto3/v2" "github.com/jackc/pgproto3/v2"
"github.com/jackc/pgservicefile" "github.com/jackc/pgservicefile"
errors "golang.org/x/xerrors"
) )
type AfterConnectFunc func(ctx context.Context, pgconn *PgConn) error 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) h, p, err := net.SplitHostPort(host)
if err != nil { 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) hosts = append(hosts, h)
ports = append(ports, p) ports = append(ports, p)
@ -617,7 +617,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) {
caPath := sslrootcert caPath := sslrootcert
caCert, err := ioutil.ReadFile(caPath) caCert, err := ioutil.ReadFile(caPath)
if err != nil { 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) { if !caCertPool.AppendCertsFromPEM(caCert) {
@ -635,7 +635,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) {
if sslcert != "" && sslkey != "" { if sslcert != "" && sslkey != "" {
cert, err := tls.LoadX509KeyPair(sslcert, sslkey) cert, err := tls.LoadX509KeyPair(sslcert, sslkey)
if err != nil { 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} tlsConfig.Certificates = []tls.Certificate{cert}

View File

@ -2,13 +2,12 @@ package pgconn
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"net/url" "net/url"
"regexp" "regexp"
"strings" "strings"
errors "golang.org/x/xerrors"
) )
// SafeToRetry checks if the err is guaranteed to have occurred before sending any data to the server. // SafeToRetry checks if the err is guaranteed to have occurred before sending any data to the server.

1
go.mod
View File

@ -12,5 +12,4 @@ require (
github.com/stretchr/testify v1.5.1 github.com/stretchr/testify v1.5.1
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/text v0.3.3 golang.org/x/text v0.3.3
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
) )

View File

@ -6,6 +6,8 @@ import (
"crypto/tls" "crypto/tls"
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"errors"
"fmt"
"io" "io"
"math" "math"
"net" "net"
@ -16,7 +18,6 @@ import (
"github.com/jackc/pgconn/internal/ctxwatch" "github.com/jackc/pgconn/internal/ctxwatch"
"github.com/jackc/pgio" "github.com/jackc/pgio"
"github.com/jackc/pgproto3/v2" "github.com/jackc/pgproto3/v2"
errors "golang.org/x/xerrors"
) )
const ( const (
@ -1043,7 +1044,7 @@ func (pgConn *PgConn) execExtendedPrefix(ctx context.Context, paramValues [][]by
} }
if len(paramValues) > math.MaxUint16 { 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 result.closed = true
pgConn.unlock() pgConn.unlock()
return result return result

View File

@ -5,6 +5,7 @@ import (
"compress/gzip" "compress/gzip"
"context" "context"
"crypto/tls" "crypto/tls"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -17,12 +18,9 @@ import (
"testing" "testing"
"time" "time"
"github.com/jackc/pgmock"
"github.com/jackc/pgconn" "github.com/jackc/pgconn"
"github.com/jackc/pgmock"
"github.com/jackc/pgproto3/v2" "github.com/jackc/pgproto3/v2"
errors "golang.org/x/xerrors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )