diff --git a/etcdctl/ctlv3/command/auth_command.go b/etcdctl/ctlv3/command/auth_command.go index 0e443450013..13ccda44d16 100644 --- a/etcdctl/ctlv3/command/auth_command.go +++ b/etcdctl/ctlv3/command/auth_command.go @@ -15,6 +15,7 @@ package command import ( + "errors" "fmt" "github.com/spf13/cobra" @@ -82,7 +83,7 @@ func authEnableCommandFunc(cmd *cobra.Command, args []string) { if _, err = cli.AuthEnable(ctx); err == nil { break } - if err == rpctypes.ErrRootRoleNotExist { + if errors.Is(err, rpctypes.ErrRootRoleNotExist) { if _, err = cli.RoleAdd(ctx, "root"); err != nil { break } diff --git a/etcdctl/ctlv3/command/ep_command.go b/etcdctl/ctlv3/command/ep_command.go index a5ee32989a9..22968ab057a 100644 --- a/etcdctl/ctlv3/command/ep_command.go +++ b/etcdctl/ctlv3/command/ep_command.go @@ -270,7 +270,7 @@ func endpointsFromCluster(cmd *cobra.Command) []string { }() membs, err := c.MemberList(ctx) if err != nil { - err = fmt.Errorf("failed to fetch endpoints from etcd cluster member list: %v", err) + err = fmt.Errorf("failed to fetch endpoints from etcd cluster member list: %w", err) cobrautl.ExitWithError(cobrautl.ExitError, err) } diff --git a/etcdctl/ctlv3/command/lease_command.go b/etcdctl/ctlv3/command/lease_command.go index e8aa2841071..3d5094b3512 100644 --- a/etcdctl/ctlv3/command/lease_command.go +++ b/etcdctl/ctlv3/command/lease_command.go @@ -61,14 +61,14 @@ func leaseGrantCommandFunc(cmd *cobra.Command, args []string) { ttl, err := strconv.ParseInt(args[0], 10, 64) if err != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad TTL (%v)", err)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad TTL (%w)", err)) } ctx, cancel := commandCtx(cmd) resp, err := mustClientFromCmd(cmd).Grant(ctx, ttl) cancel() if err != nil { - cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to grant lease (%v)", err)) + cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to grant lease (%w)", err)) } display.Grant(*resp) } @@ -96,7 +96,7 @@ func leaseRevokeCommandFunc(cmd *cobra.Command, args []string) { resp, err := mustClientFromCmd(cmd).Revoke(ctx, id) cancel() if err != nil { - cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to revoke lease (%v)", err)) + cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to revoke lease (%w)", err)) } display.Revoke(id, *resp) } @@ -202,7 +202,7 @@ func leaseKeepAliveCommandFunc(cmd *cobra.Command, args []string) { func leaseFromArgs(arg string) v3.LeaseID { id, err := strconv.ParseInt(arg, 16, 64) if err != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID arg (%w), expecting ID in Hex", err)) } return v3.LeaseID(id) } diff --git a/etcdctl/ctlv3/command/lock_command.go b/etcdctl/ctlv3/command/lock_command.go index 1522773c21a..64fb0ee8192 100644 --- a/etcdctl/ctlv3/command/lock_command.go +++ b/etcdctl/ctlv3/command/lock_command.go @@ -59,7 +59,8 @@ func getExitCodeFromError(err error) int { return cobrautl.ExitSuccess } - if exitErr, ok := err.(*exec.ExitError); ok { + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { return status.ExitStatus() } diff --git a/etcdctl/ctlv3/command/member_command.go b/etcdctl/ctlv3/command/member_command.go index 9cf95e84082..256bf2b9c7b 100644 --- a/etcdctl/ctlv3/command/member_command.go +++ b/etcdctl/ctlv3/command/member_command.go @@ -188,7 +188,7 @@ func memberRemoveCommandFunc(cmd *cobra.Command, args []string) { id, err := strconv.ParseUint(args[0], 16, 64) if err != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%w), expecting ID in Hex", err)) } ctx, cancel := commandCtx(cmd) @@ -208,7 +208,7 @@ func memberUpdateCommandFunc(cmd *cobra.Command, args []string) { id, err := strconv.ParseUint(args[0], 16, 64) if err != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%w), expecting ID in Hex", err)) } if len(memberPeerURLs) == 0 { @@ -251,7 +251,7 @@ func memberPromoteCommandFunc(cmd *cobra.Command, args []string) { id, err := strconv.ParseUint(args[0], 16, 64) if err != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%w), expecting ID in Hex", err)) } ctx, cancel := commandCtx(cmd) diff --git a/etcdctl/ctlv3/command/put_command.go b/etcdctl/ctlv3/command/put_command.go index 1d207bb8388..4814db55990 100644 --- a/etcdctl/ctlv3/command/put_command.go +++ b/etcdctl/ctlv3/command/put_command.go @@ -99,7 +99,7 @@ func getPutOp(args []string) (string, string, []clientv3.OpOption) { id, err := strconv.ParseInt(leaseStr, 16, 64) if err != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID (%v), expecting ID in Hex", err)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID (%w), expecting ID in Hex", err)) } var opts []clientv3.OpOption diff --git a/etcdctl/ctlv3/command/txn_command.go b/etcdctl/ctlv3/command/txn_command.go index a898430d15a..5433f82bda6 100644 --- a/etcdctl/ctlv3/command/txn_command.go +++ b/etcdctl/ctlv3/command/txn_command.go @@ -194,7 +194,7 @@ func ParseCompare(line string) (*clientv3.Cmp, error) { return nil, fmt.Errorf("malformed comparison: %s; got %s(%q) %s %q", line, target, key, op, val) } if serr != nil { - return nil, fmt.Errorf("malformed comparison: %s (%v)", line, serr) + return nil, fmt.Errorf("malformed comparison: %s (%w)", line, serr) } var ( diff --git a/etcdctl/ctlv3/command/user_command.go b/etcdctl/ctlv3/command/user_command.go index ee3f55a2a47..9aec9fab5dc 100644 --- a/etcdctl/ctlv3/command/user_command.go +++ b/etcdctl/ctlv3/command/user_command.go @@ -280,7 +280,7 @@ func readPasswordInteractive(name string) string { prompt1 := fmt.Sprintf("Password of %s: ", name) password1, err1 := speakeasy.Ask(prompt1) if err1 != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %s", err1)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %w", err1)) } if len(password1) == 0 { @@ -290,7 +290,7 @@ func readPasswordInteractive(name string) string { prompt2 := fmt.Sprintf("Type password of %s again for confirmation: ", name) password2, err2 := speakeasy.Ask(prompt2) if err2 != nil { - cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %s", err2)) + cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %w", err2)) } if password1 != password2 { diff --git a/etcdctl/ctlv3/command/watch_command.go b/etcdctl/ctlv3/command/watch_command.go index 024bb6d618a..fa8fc72d82f 100644 --- a/etcdctl/ctlv3/command/watch_command.go +++ b/etcdctl/ctlv3/command/watch_command.go @@ -99,7 +99,7 @@ func watchInteractiveFunc(cmd *cobra.Command, osArgs []string, envKey, envRange for { l, err := reader.ReadString('\n') if err != nil { - cobrautl.ExitWithError(cobrautl.ExitInvalidInput, fmt.Errorf("error reading watch request line: %v", err)) + cobrautl.ExitWithError(cobrautl.ExitInvalidInput, fmt.Errorf("error reading watch request line: %w", err)) } l = strings.TrimSuffix(l, "\n") diff --git a/etcdctl/ctlv3/command/watch_command_test.go b/etcdctl/ctlv3/command/watch_command_test.go index 2292deadcbb..ad4668606ec 100644 --- a/etcdctl/ctlv3/command/watch_command_test.go +++ b/etcdctl/ctlv3/command/watch_command_test.go @@ -15,6 +15,7 @@ package command import ( + "errors" "reflect" "testing" ) @@ -534,7 +535,7 @@ func Test_parseWatchArgs(t *testing.T) { } for i, ts := range tt { watchArgs, execArgs, err := parseWatchArgs(ts.osArgs, ts.commandArgs, ts.envKey, ts.envRange, ts.interactive) - if err != ts.err { + if !errors.Is(err, ts.err) { t.Fatalf("#%d: error expected %v, got %v", i, ts.err, err) } if !reflect.DeepEqual(watchArgs, ts.watchArgs) { diff --git a/etcdutl/etcdutl/defrag_command.go b/etcdutl/etcdutl/defrag_command.go index d8077ae8bfb..0d100025954 100644 --- a/etcdutl/etcdutl/defrag_command.go +++ b/etcdutl/etcdutl/defrag_command.go @@ -47,7 +47,7 @@ func defragCommandFunc(cmd *cobra.Command, args []string) { err := DefragData(defragDataDir) if err != nil { cobrautl.ExitWithError(cobrautl.ExitError, - fmt.Errorf("Failed to defragment etcd data[%s] (%v)", defragDataDir, err)) + fmt.Errorf("Failed to defragment etcd data[%s] (%w)", defragDataDir, err)) } } diff --git a/etcdutl/etcdutl/migrate_command.go b/etcdutl/etcdutl/migrate_command.go index 154ba466a35..15188984f85 100644 --- a/etcdutl/etcdutl/migrate_command.go +++ b/etcdutl/etcdutl/migrate_command.go @@ -85,7 +85,7 @@ func (o *migrateOptions) Config() (*migrateConfig, error) { } c.targetVersion, err = semver.NewVersion(o.targetVersion + ".0") if err != nil { - return nil, fmt.Errorf("failed to parse target version: %v", err) + return nil, fmt.Errorf("failed to parse target version: %w", err) } if c.targetVersion.LessThan(version.V3_5) { return nil, fmt.Errorf(`target version %q not supported. Minimal "3.5"`, storageVersionToString(c.targetVersion)) @@ -97,12 +97,12 @@ func (o *migrateOptions) Config() (*migrateConfig, error) { walPath := datadir.ToWALDir(o.dataDir) w, err := wal.OpenForRead(c.lg, walPath, walpb.Snapshot{}) if err != nil { - return nil, fmt.Errorf(`failed to open wal: %v`, err) + return nil, fmt.Errorf(`failed to open wal: %w`, err) } defer w.Close() c.walVersion, err = wal.ReadWALVersion(w) if err != nil { - return nil, fmt.Errorf(`failed to read wal: %v`, err) + return nil, fmt.Errorf(`failed to read wal: %w`, err) } return c, nil