Skip to content

Commit

Permalink
Merge pull request #18614 from redwrasse/redwrasse/client/rest-of-err…
Browse files Browse the repository at this point in the history
…ors-is

client: remaining errors.Is conversions
  • Loading branch information
jmhbnz authored Sep 25, 2024
2 parents 5704c61 + ecc2c5e commit 1a08fb2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions client/internal/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ if err != nil {
kapi := client.NewKeysAPI(c)
resp, err := kapi.Set(ctx, "test", "bar", nil)
if err != nil {
if err == context.Canceled {
var cerr *client.ClusterError
if errors.Is(err, context.Canceled) {
// ctx is canceled by another routine
} else if err == context.DeadlineExceeded {
} else if errors.Is(err, context.DeadlineExceeded) {
// ctx is attached with a deadline and it exceeded
} else if cerr, ok := err.(*client.ClusterError); ok {
} else if errors.As(err, &cerr) {
// process (cerr.Errors)
} else {
// bad cluster endpoints, which are not etcd servers
Expand Down
3 changes: 2 additions & 1 deletion client/pkg/fileutil/preallocate_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package fileutil

import (
"errors"
"os"
"syscall"

Expand All @@ -39,7 +40,7 @@ func preallocFixed(f *os.File, sizeInBytes int64) error {
Length: sizeInBytes,
}
err := unix.FcntlFstore(f.Fd(), unix.F_PREALLOCATE, fstore)
if err == nil || err == unix.ENOTSUP {
if err == nil || errors.Is(err, unix.ENOTSUP) {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion client/v3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (c *Client) autoSync() {
ctx, cancel := context.WithTimeout(c.ctx, 5*time.Second)
err := c.Sync(ctx)
cancel()
if err != nil && err != c.ctx.Err() {
if err != nil && !errors.Is(err, c.ctx.Err()) {
c.lg.Info("Auto sync endpoints failed.", zap.Error(err))
}
}
Expand Down
6 changes: 3 additions & 3 deletions client/v3/retry_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ func (c *Client) streamClientInterceptor(optFuncs ...retryOption) grpc.StreamCli
// shouldRefreshToken checks whether there's a need to refresh the token based on the error and callOptions,
// and returns a boolean value.
func (c *Client) shouldRefreshToken(err error, callOpts *options) bool {
if rpctypes.Error(err) == rpctypes.ErrUserEmpty {
if errors.Is(rpctypes.Error(err), rpctypes.ErrUserEmpty) {
// refresh the token when username, password is present but the server returns ErrUserEmpty
// which is possible when the client token is cleared somehow
return c.authTokenBundle != nil // equal to c.Username != "" && c.Password != ""
}

return callOpts.retryAuth &&
(rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken || rpctypes.Error(err) == rpctypes.ErrAuthOldRevision)
(errors.Is(rpctypes.Error(err), rpctypes.ErrInvalidAuthToken) || errors.Is(rpctypes.Error(err), rpctypes.ErrAuthOldRevision))
}

func (c *Client) refreshToken(ctx context.Context) error {
Expand Down Expand Up @@ -254,7 +254,7 @@ func (s *serverStreamingRetryingStream) receiveMsgAndIndicateRetry(m any) (bool,
wasGood := s.receivedGood
s.mu.RUnlock()
err := s.getStream().RecvMsg(m)
if err == nil || err == io.EOF {
if err == nil || errors.Is(err, io.EOF) {
s.mu.Lock()
s.receivedGood = true
s.mu.Unlock()
Expand Down

0 comments on commit 1a08fb2

Please sign in to comment.