mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #18614 from redwrasse/redwrasse/client/rest-of-errors-is
client: remaining errors.Is conversions
This commit is contained in:
commit
1a08fb2809
@ -88,11 +88,12 @@ if err != nil {
|
|||||||
kapi := client.NewKeysAPI(c)
|
kapi := client.NewKeysAPI(c)
|
||||||
resp, err := kapi.Set(ctx, "test", "bar", nil)
|
resp, err := kapi.Set(ctx, "test", "bar", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == context.Canceled {
|
var cerr *client.ClusterError
|
||||||
|
if errors.Is(err, context.Canceled) {
|
||||||
// ctx is canceled by another routine
|
// 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
|
// 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)
|
// process (cerr.Errors)
|
||||||
} else {
|
} else {
|
||||||
// bad cluster endpoints, which are not etcd servers
|
// bad cluster endpoints, which are not etcd servers
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
package fileutil
|
package fileutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ func preallocFixed(f *os.File, sizeInBytes int64) error {
|
|||||||
Length: sizeInBytes,
|
Length: sizeInBytes,
|
||||||
}
|
}
|
||||||
err := unix.FcntlFstore(f.Fd(), unix.F_PREALLOCATE, fstore)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -220,7 +220,7 @@ func (c *Client) autoSync() {
|
|||||||
ctx, cancel := context.WithTimeout(c.ctx, 5*time.Second)
|
ctx, cancel := context.WithTimeout(c.ctx, 5*time.Second)
|
||||||
err := c.Sync(ctx)
|
err := c.Sync(ctx)
|
||||||
cancel()
|
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))
|
c.lg.Info("Auto sync endpoints failed.", zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,
|
// shouldRefreshToken checks whether there's a need to refresh the token based on the error and callOptions,
|
||||||
// and returns a boolean value.
|
// and returns a boolean value.
|
||||||
func (c *Client) shouldRefreshToken(err error, callOpts *options) bool {
|
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
|
// refresh the token when username, password is present but the server returns ErrUserEmpty
|
||||||
// which is possible when the client token is cleared somehow
|
// which is possible when the client token is cleared somehow
|
||||||
return c.authTokenBundle != nil // equal to c.Username != "" && c.Password != ""
|
return c.authTokenBundle != nil // equal to c.Username != "" && c.Password != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return callOpts.retryAuth &&
|
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 {
|
func (c *Client) refreshToken(ctx context.Context) error {
|
||||||
@ -254,7 +254,7 @@ func (s *serverStreamingRetryingStream) receiveMsgAndIndicateRetry(m any) (bool,
|
|||||||
wasGood := s.receivedGood
|
wasGood := s.receivedGood
|
||||||
s.mu.RUnlock()
|
s.mu.RUnlock()
|
||||||
err := s.getStream().RecvMsg(m)
|
err := s.getStream().RecvMsg(m)
|
||||||
if err == nil || err == io.EOF {
|
if err == nil || errors.Is(err, io.EOF) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
s.receivedGood = true
|
s.receivedGood = true
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user