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/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) {

View File

@ -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}

View File

@ -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.

1
go.mod
View File

@ -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
)

View File

@ -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

View File

@ -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"
)