Skip to content

Commit

Permalink
all: remove refs to deprecated xerrors
Browse files Browse the repository at this point in the history
  • Loading branch information
testwill committed Jun 14, 2023
1 parent 1db413f commit 2e4fad4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
8 changes: 4 additions & 4 deletions gcerrors/errors.go
Expand Up @@ -18,9 +18,9 @@ package gcerrors

import (
"context"
"errors"

"gocloud.dev/internal/gcerr"
"golang.org/x/xerrors"
)

// An ErrorCode describes the error's category. Programs should act upon an error's
Expand Down Expand Up @@ -78,13 +78,13 @@ func Code(err error) ErrorCode {
return OK
}
var e *gcerr.Error
if xerrors.As(err, &e) {
if errors.As(err, &e) {
return e.Code
}
if xerrors.Is(err, context.Canceled) {
if errors.Is(err, context.Canceled) {
return Canceled
}
if xerrors.Is(err, context.DeadlineExceeded) {
if errors.Is(err, context.DeadlineExceeded) {
return DeadlineExceeded
}
return Unknown
Expand Down
9 changes: 5 additions & 4 deletions internal/gcerr/gcerr.go
Expand Up @@ -17,6 +17,7 @@ package gcerr

import (
"context"
"errors"
"fmt"
"io"
"reflect"
Expand Down Expand Up @@ -140,17 +141,17 @@ func Newf(c ErrorCode, err error, format string, args ...interface{}) *Error {
// It returns true if err is a retry error, a context error, io.EOF, or if it wraps
// one of those.
func DoNotWrap(err error) bool {
if xerrors.Is(err, io.EOF) {
if errors.Is(err, io.EOF) {
return true
}
if xerrors.Is(err, context.Canceled) {
if errors.Is(err, context.Canceled) {
return true
}
if xerrors.Is(err, context.DeadlineExceeded) {
if errors.Is(err, context.DeadlineExceeded) {
return true
}
var r *retry.ContextError
return xerrors.As(err, &r)
return errors.As(err, &r)
}

// GRPCCode extracts the gRPC status code and converts it into an ErrorCode.
Expand Down
3 changes: 1 addition & 2 deletions internal/retry/retry_test.go
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"github.com/googleapis/gax-go/v2"
"golang.org/x/xerrors"
)

// Errors to distinguish retryable and non-retryable cases.
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestErrorsIs(t *testing.T) {
FuncErr: os.ErrExist,
}
for _, target := range []error{err, context.Canceled, os.ErrExist} {
if !xerrors.Is(err, target) {
if !errors.Is(err, target) {
t.Errorf("xerrors.Is(%v) == false, want true", target)
}
}
Expand Down
4 changes: 1 addition & 3 deletions pubsub/acks_test.go
Expand Up @@ -21,8 +21,6 @@ import (
"testing"
"time"

"golang.org/x/xerrors"

"gocloud.dev/gcerrors"
"gocloud.dev/internal/gcerr"
"gocloud.dev/pubsub"
Expand Down Expand Up @@ -435,7 +433,7 @@ func TestReceiveReturnsAckErrorOnNoMoreMessages(t *testing.T) {
if got := gcerrors.Code(err); got != gcerrors.Internal {
t.Fatalf("error code = %v; want %v", got, gcerrors.Internal)
}
if got := xerrors.Unwrap(err); got != serr {
if got := errors.Unwrap(err); got != serr {
t.Errorf("error = %v; want %v", got, serr)
}
}
4 changes: 2 additions & 2 deletions pubsub/benchmark_test.go
Expand Up @@ -16,6 +16,7 @@ package pubsub

import (
"context"
"errors"
"fmt"
"math/rand"
"sync"
Expand All @@ -24,7 +25,6 @@ import (

"gocloud.dev/pubsub/driver"
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"
)

const (
Expand Down Expand Up @@ -281,7 +281,7 @@ func runBenchmark(t *testing.T, description string, numGoRoutines int, receivePr
// Each goroutine loops until ctx is canceled.
for {
m, err := sub.Receive(ctx)
if xerrors.Is(err, context.DeadlineExceeded) {
if errors.Is(err, context.DeadlineExceeded) {
return nil
}
if err != nil {
Expand Down

0 comments on commit 2e4fad4

Please sign in to comment.