mirror of https://github.com/jackc/pgx.git
Unwrap errors in normalizeTimeoutError
parent
2daeb8dc5f
commit
9ab9e3c40b
|
@ -107,14 +107,15 @@ func (e *parseConfigError) Unwrap() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeTimeoutError(ctx context.Context, err error) error {
|
func normalizeTimeoutError(ctx context.Context, err error) error {
|
||||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
var netErr net.Error
|
||||||
|
if errors.As(err, &netErr) && netErr.Timeout() {
|
||||||
if ctx.Err() == context.Canceled {
|
if ctx.Err() == context.Canceled {
|
||||||
// Since the timeout was caused by a context cancellation, the actual error is context.Canceled not the timeout error.
|
// Since the timeout was caused by a context cancellation, the actual error is context.Canceled not the timeout error.
|
||||||
return context.Canceled
|
return context.Canceled
|
||||||
} else if ctx.Err() == context.DeadlineExceeded {
|
} else if ctx.Err() == context.DeadlineExceeded {
|
||||||
return &errTimeout{err: ctx.Err()}
|
return &errTimeout{err: ctx.Err()}
|
||||||
} else {
|
} else {
|
||||||
return &errTimeout{err: err}
|
return &errTimeout{err: netErr}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue