Make timeout error private

Signed-off-by: Michael Darr <michael.e.darr@gmail.com>
query-exec-mode
Michael Darr 2021-07-06 21:44:44 -04:00 committed by Jack Christensen
parent 9a9830c00d
commit a50d96d491
2 changed files with 11 additions and 11 deletions

View File

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

View File

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