diff --git a/storage/integration_test.go b/storage/integration_test.go index 0b90c7dee64..a0679ecc60a 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -3206,14 +3206,12 @@ func TestIntegration_CancelWrite(t *testing.T) { cancel() // The next Write should return context.Canceled. _, err = w.Write(buf) - // TODO: Once we drop support for Go versions < 1.13, use errors.Is() to - // check for context cancellation instead. - if err != context.Canceled && !strings.Contains(err.Error(), "context canceled") { + if !xerrors.Is(err, context.Canceled) { t.Fatalf("got %v, wanted context.Canceled", err) } // The Close should too. err = w.Close() - if err != context.Canceled && !strings.Contains(err.Error(), "context canceled") { + if !xerrors.Is(err, context.Canceled) { t.Fatalf("got %v, wanted context.Canceled", err) } } @@ -3865,7 +3863,7 @@ func TestIntegration_ReaderCancel(t *testing.T) { buf := make([]byte, 1000) _, readErr = r.Read(buf) if readErr != nil { - if readErr == context.Canceled { + if xerrors.Is(readErr, context.Canceled) { return } break diff --git a/storage/invoke.go b/storage/invoke.go index 2ecf48fffd4..0c44c2db14c 100644 --- a/storage/invoke.go +++ b/storage/invoke.go @@ -36,7 +36,7 @@ func runWithRetry(ctx context.Context, call func() error) error { return true, nil } if shouldRetry(err) { - return false, nil + return false, err } return true, err }) diff --git a/storage/writer.go b/storage/writer.go index ff30ff78bd2..a0ca9ae51a0 100644 --- a/storage/writer.go +++ b/storage/writer.go @@ -24,6 +24,7 @@ import ( "unicode/utf8" "github.com/golang/protobuf/proto" + "golang.org/x/xerrors" "google.golang.org/api/googleapi" raw "google.golang.org/api/storage/v1" storagepb "google.golang.org/genproto/googleapis/storage/v2" @@ -217,7 +218,7 @@ func (w *Writer) Write(p []byte) (n int, err error) { // Preserve existing functionality that when context is canceled, Write will return // context.Canceled instead of "io: read/write on closed pipe". This hides the // pipe implementation detail from users and makes Write seem as though it's an RPC. - if werr == context.Canceled || werr == context.DeadlineExceeded { + if xerrors.Is(werr, context.Canceled) || xerrors.Is(werr, context.DeadlineExceeded){ return n, werr } }