diff --git a/errors.go b/errors.go index ab83b3a5..64401d65 100644 --- a/errors.go +++ b/errors.go @@ -20,7 +20,7 @@ func SafeToRetry(err error) bool { // Timeout checks if err was was caused by a timeout. To be specific, it is true if err was caused within pgconn by a // context.Canceled, context.DeadlineExceeded or an implementer of net.Error where Timeout() is true. func Timeout(err error) bool { - var timeoutErr *ErrTimeout + var timeoutErr *errTimeout return errors.As(err, &timeoutErr) } @@ -129,21 +129,21 @@ func (e *pgconnError) Unwrap() error { return e.err } -// ErrTimeout occurs when an error was caused by a timeout. Specifically, it wraps an error which is +// errTimeout occurs when an error was caused by a timeout. Specifically, it wraps an error which is // context.Canceled, context.DeadlineExceeded, or an implementer of net.Error where Timeout() is true. -type ErrTimeout struct { +type errTimeout struct { err error } -func (e *ErrTimeout) Error() string { +func (e *errTimeout) Error() string { return fmt.Sprintf("timeout: %s", e.err.Error()) } -func (e *ErrTimeout) SafeToRetry() bool { +func (e *errTimeout) SafeToRetry() bool { return SafeToRetry(e.err) } -func (e *ErrTimeout) Unwrap() error { +func (e *errTimeout) Unwrap() error { return e.err } @@ -163,9 +163,9 @@ func (e *contextAlreadyDoneError) Unwrap() error { return e.err } -// newContextAlreadyDoneError double-wraps a context error in `contextAlreadyDoneError` and `ErrTimeout`. +// newContextAlreadyDoneError double-wraps a context error in `contextAlreadyDoneError` and `errTimeout`. func newContextAlreadyDoneError(ctx context.Context) (err error) { - return &ErrTimeout{&contextAlreadyDoneError{err: ctx.Err()}} + return &errTimeout{&contextAlreadyDoneError{err: ctx.Err()}} } type writeError struct { diff --git a/pgconn.go b/pgconn.go index 74e24257..a17a108d 100644 --- a/pgconn.go +++ b/pgconn.go @@ -219,7 +219,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig if err != nil { var netErr net.Error if errors.As(err, &netErr) && netErr.Timeout() { - err = &ErrTimeout{err: err} + err = &errTimeout{err: err} } return nil, &connectError{config: config, msg: "dial error", err: err} } @@ -470,7 +470,7 @@ func (pgConn *PgConn) peekMessage() (pgproto3.BackendMessage, error) { if !(isNetErr && netErr.Timeout()) { pgConn.asyncClose() } else if isNetErr && netErr.Timeout() { - err = &ErrTimeout{err: err} + err = &errTimeout{err: err} } return nil, err @@ -490,7 +490,7 @@ func (pgConn *PgConn) receiveMessage() (pgproto3.BackendMessage, error) { if !(isNetErr && netErr.Timeout()) { pgConn.asyncClose() } else if isNetErr && netErr.Timeout() { - err = &ErrTimeout{err: err} + err = &errTimeout{err: err} } return nil, err