From 9a9830c00d579aaa709b095acd2ab96162e3a564 Mon Sep 17 00:00:00 2001 From: Michael Darr Date: Tue, 6 Jul 2021 15:43:26 -0400 Subject: [PATCH] Always double-wrap contextAlreadyDoneError Signed-off-by: Michael Darr --- errors.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/errors.go b/errors.go index 0bb322cd..ab83b3a5 100644 --- a/errors.go +++ b/errors.go @@ -163,15 +163,9 @@ func (e *contextAlreadyDoneError) Unwrap() error { return e.err } -// newContextAlreadyDoneError wraps a context error in `contextAlreadyDoneError`. If the context was cancelled or its -// deadline passed, the returned error is also wrapped by `ErrTimeout`. +// newContextAlreadyDoneError double-wraps a context error in `contextAlreadyDoneError` and `ErrTimeout`. func newContextAlreadyDoneError(ctx context.Context) (err error) { - ctxErr := ctx.Err() - err = &contextAlreadyDoneError{err: ctxErr} - if ctxErr != nil { - err = &ErrTimeout{err: err} - } - return err + return &ErrTimeout{&contextAlreadyDoneError{err: ctx.Err()}} } type writeError struct {