Skip to content

Commit ee88ecc

Browse files
authored
Merge pull request #18813 from mmorel-35/etcd-tl/errorlint
fix: enable errorlint in etcdctl and etcdutl directories
2 parents 6883308 + ff632e4 commit ee88ecc

12 files changed

+23
-20
lines changed

etcdctl/ctlv3/command/auth_command.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package command
1616

1717
import (
18+
"errors"
1819
"fmt"
1920

2021
"github.com/spf13/cobra"
@@ -82,7 +83,7 @@ func authEnableCommandFunc(cmd *cobra.Command, args []string) {
8283
if _, err = cli.AuthEnable(ctx); err == nil {
8384
break
8485
}
85-
if err == rpctypes.ErrRootRoleNotExist {
86+
if errors.Is(err, rpctypes.ErrRootRoleNotExist) {
8687
if _, err = cli.RoleAdd(ctx, "root"); err != nil {
8788
break
8889
}

etcdctl/ctlv3/command/ep_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func endpointsFromCluster(cmd *cobra.Command) []string {
270270
}()
271271
membs, err := c.MemberList(ctx)
272272
if err != nil {
273-
err = fmt.Errorf("failed to fetch endpoints from etcd cluster member list: %v", err)
273+
err = fmt.Errorf("failed to fetch endpoints from etcd cluster member list: %w", err)
274274
cobrautl.ExitWithError(cobrautl.ExitError, err)
275275
}
276276

etcdctl/ctlv3/command/lease_command.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ func leaseGrantCommandFunc(cmd *cobra.Command, args []string) {
6161

6262
ttl, err := strconv.ParseInt(args[0], 10, 64)
6363
if err != nil {
64-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad TTL (%v)", err))
64+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad TTL (%w)", err))
6565
}
6666

6767
ctx, cancel := commandCtx(cmd)
6868
resp, err := mustClientFromCmd(cmd).Grant(ctx, ttl)
6969
cancel()
7070
if err != nil {
71-
cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to grant lease (%v)", err))
71+
cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to grant lease (%w)", err))
7272
}
7373
display.Grant(*resp)
7474
}
@@ -96,7 +96,7 @@ func leaseRevokeCommandFunc(cmd *cobra.Command, args []string) {
9696
resp, err := mustClientFromCmd(cmd).Revoke(ctx, id)
9797
cancel()
9898
if err != nil {
99-
cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to revoke lease (%v)", err))
99+
cobrautl.ExitWithError(cobrautl.ExitError, fmt.Errorf("failed to revoke lease (%w)", err))
100100
}
101101
display.Revoke(id, *resp)
102102
}
@@ -202,7 +202,7 @@ func leaseKeepAliveCommandFunc(cmd *cobra.Command, args []string) {
202202
func leaseFromArgs(arg string) v3.LeaseID {
203203
id, err := strconv.ParseInt(arg, 16, 64)
204204
if err != nil {
205-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err))
205+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID arg (%w), expecting ID in Hex", err))
206206
}
207207
return v3.LeaseID(id)
208208
}

etcdctl/ctlv3/command/lock_command.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func getExitCodeFromError(err error) int {
5959
return cobrautl.ExitSuccess
6060
}
6161

62-
if exitErr, ok := err.(*exec.ExitError); ok {
62+
var exitErr *exec.ExitError
63+
if errors.As(err, &exitErr) {
6364
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
6465
return status.ExitStatus()
6566
}

etcdctl/ctlv3/command/member_command.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func memberRemoveCommandFunc(cmd *cobra.Command, args []string) {
188188

189189
id, err := strconv.ParseUint(args[0], 16, 64)
190190
if err != nil {
191-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err))
191+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%w), expecting ID in Hex", err))
192192
}
193193

194194
ctx, cancel := commandCtx(cmd)
@@ -208,7 +208,7 @@ func memberUpdateCommandFunc(cmd *cobra.Command, args []string) {
208208

209209
id, err := strconv.ParseUint(args[0], 16, 64)
210210
if err != nil {
211-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err))
211+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%w), expecting ID in Hex", err))
212212
}
213213

214214
if len(memberPeerURLs) == 0 {
@@ -251,7 +251,7 @@ func memberPromoteCommandFunc(cmd *cobra.Command, args []string) {
251251

252252
id, err := strconv.ParseUint(args[0], 16, 64)
253253
if err != nil {
254-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err))
254+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad member ID arg (%w), expecting ID in Hex", err))
255255
}
256256

257257
ctx, cancel := commandCtx(cmd)

etcdctl/ctlv3/command/put_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func getPutOp(args []string) (string, string, []clientv3.OpOption) {
9999

100100
id, err := strconv.ParseInt(leaseStr, 16, 64)
101101
if err != nil {
102-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID (%v), expecting ID in Hex", err))
102+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("bad lease ID (%w), expecting ID in Hex", err))
103103
}
104104

105105
var opts []clientv3.OpOption

etcdctl/ctlv3/command/txn_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func ParseCompare(line string) (*clientv3.Cmp, error) {
194194
return nil, fmt.Errorf("malformed comparison: %s; got %s(%q) %s %q", line, target, key, op, val)
195195
}
196196
if serr != nil {
197-
return nil, fmt.Errorf("malformed comparison: %s (%v)", line, serr)
197+
return nil, fmt.Errorf("malformed comparison: %s (%w)", line, serr)
198198
}
199199

200200
var (

etcdctl/ctlv3/command/user_command.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func readPasswordInteractive(name string) string {
280280
prompt1 := fmt.Sprintf("Password of %s: ", name)
281281
password1, err1 := speakeasy.Ask(prompt1)
282282
if err1 != nil {
283-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %s", err1))
283+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %w", err1))
284284
}
285285

286286
if len(password1) == 0 {
@@ -290,7 +290,7 @@ func readPasswordInteractive(name string) string {
290290
prompt2 := fmt.Sprintf("Type password of %s again for confirmation: ", name)
291291
password2, err2 := speakeasy.Ask(prompt2)
292292
if err2 != nil {
293-
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %s", err2))
293+
cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("failed to ask password: %w", err2))
294294
}
295295

296296
if password1 != password2 {

etcdctl/ctlv3/command/watch_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func watchInteractiveFunc(cmd *cobra.Command, osArgs []string, envKey, envRange
9999
for {
100100
l, err := reader.ReadString('\n')
101101
if err != nil {
102-
cobrautl.ExitWithError(cobrautl.ExitInvalidInput, fmt.Errorf("error reading watch request line: %v", err))
102+
cobrautl.ExitWithError(cobrautl.ExitInvalidInput, fmt.Errorf("error reading watch request line: %w", err))
103103
}
104104
l = strings.TrimSuffix(l, "\n")
105105

etcdctl/ctlv3/command/watch_command_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package command
1616

1717
import (
18+
"errors"
1819
"reflect"
1920
"testing"
2021
)
@@ -534,7 +535,7 @@ func Test_parseWatchArgs(t *testing.T) {
534535
}
535536
for i, ts := range tt {
536537
watchArgs, execArgs, err := parseWatchArgs(ts.osArgs, ts.commandArgs, ts.envKey, ts.envRange, ts.interactive)
537-
if err != ts.err {
538+
if !errors.Is(err, ts.err) {
538539
t.Fatalf("#%d: error expected %v, got %v", i, ts.err, err)
539540
}
540541
if !reflect.DeepEqual(watchArgs, ts.watchArgs) {

etcdutl/etcdutl/defrag_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func defragCommandFunc(cmd *cobra.Command, args []string) {
4747
err := DefragData(defragDataDir)
4848
if err != nil {
4949
cobrautl.ExitWithError(cobrautl.ExitError,
50-
fmt.Errorf("Failed to defragment etcd data[%s] (%v)", defragDataDir, err))
50+
fmt.Errorf("Failed to defragment etcd data[%s] (%w)", defragDataDir, err))
5151
}
5252
}
5353

etcdutl/etcdutl/migrate_command.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (o *migrateOptions) Config() (*migrateConfig, error) {
8585
}
8686
c.targetVersion, err = semver.NewVersion(o.targetVersion + ".0")
8787
if err != nil {
88-
return nil, fmt.Errorf("failed to parse target version: %v", err)
88+
return nil, fmt.Errorf("failed to parse target version: %w", err)
8989
}
9090
if c.targetVersion.LessThan(version.V3_5) {
9191
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) {
9797
walPath := datadir.ToWALDir(o.dataDir)
9898
w, err := wal.OpenForRead(c.lg, walPath, walpb.Snapshot{})
9999
if err != nil {
100-
return nil, fmt.Errorf(`failed to open wal: %v`, err)
100+
return nil, fmt.Errorf(`failed to open wal: %w`, err)
101101
}
102102
defer w.Close()
103103
c.walVersion, err = wal.ReadWALVersion(w)
104104
if err != nil {
105-
return nil, fmt.Errorf(`failed to read wal: %v`, err)
105+
return nil, fmt.Errorf(`failed to read wal: %w`, err)
106106
}
107107

108108
return c, nil

0 commit comments

Comments
 (0)