Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable errorlint linter #18818

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contrib/raftexample/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"encoding/gob"
"encoding/json"
"errors"
"log"
"strings"
"sync"
Expand Down Expand Up @@ -113,7 +114,7 @@ func (s *kvstore) getSnapshot() ([]byte, error) {

func (s *kvstore) loadSnapshot() (*raftpb.Snapshot, error) {
snapshot, err := s.snapshotter.Load()
if err == snap.ErrNoSnapshot {
if errors.Is(err, snap.ErrNoSnapshot) {
return nil, nil
}
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions contrib/raftexample/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"context"
"errors"
"fmt"
"log"
"net/http"
Expand Down Expand Up @@ -206,7 +207,7 @@ func (rc *raftNode) loadSnapshot() *raftpb.Snapshot {
log.Fatalf("raftexample: error listing snapshots (%v)", err)
}
snapshot, err := rc.snapshotter.LoadNewestAvailable(walSnaps)
if err != nil && err != snap.ErrNoSnapshot {
if err != nil && !errors.Is(err, snap.ErrNoSnapshot) {
log.Fatalf("raftexample: error loading snapshot (%v)", err)
}
return snapshot
Expand Down Expand Up @@ -391,7 +392,7 @@ func (rc *raftNode) maybeTriggerSnapshot(applyDoneC <-chan struct{}) {
compactIndex = rc.appliedIndex - snapshotCatchUpEntriesN
}
if err := rc.raftStorage.Compact(compactIndex); err != nil {
if err != raft.ErrCompacted {
if !errors.Is(err, raft.ErrCompacted) {
panic(err)
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/ctl_v3_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func TestCtlV3AuthSnapshotJWT(t *testing.T) {
func authEnable(cx ctlCtx) error {
// create root user with root role
if err := ctlV3User(cx, []string{"add", "root", "--interactive=false"}, "User root created", []string{"root"}); err != nil {
return fmt.Errorf("failed to create root user %v", err)
return fmt.Errorf("failed to create root user %w", err)
}
if err := ctlV3User(cx, []string{"grant-role", "root", "root"}, "Role root is granted to user root", nil); err != nil {
return fmt.Errorf("failed to grant root user root role %v", err)
return fmt.Errorf("failed to grant root user root role %w", err)
}
if err := ctlV3AuthEnable(cx); err != nil {
return fmt.Errorf("authEnableTest ctlV3AuthEnable error (%v)", err)
return fmt.Errorf("authEnableTest ctlV3AuthEnable error (%w)", err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func tlsInfo(t testing.TB, cfg e2e.ClientConfig) (*transport.TLSInfo, error) {
if cfg.AutoTLS {
tls, err := transport.SelfCert(zap.NewNop(), t.TempDir(), []string{"localhost"}, 1)
if err != nil {
return nil, fmt.Errorf("failed to generate cert: %s", err)
return nil, fmt.Errorf("failed to generate cert: %w", err)
}
return &tls, nil
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/v3_curl_election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func CURLWithExpected(cx ctlCtx, tests []v3cURLTest) error {
for _, t := range tests {
value := fmt.Sprintf("%v", t.value)
if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: t.endpoint, Value: value, Expected: expect.ExpectedResponse{Value: t.expected}}); err != nil {
return fmt.Errorf("endpoint (%s): error (%v), wanted %v", t.endpoint, err, t.expected)
return fmt.Errorf("endpoint (%s): error (%w), wanted %v", t.endpoint, err, t.expected)
}
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/v3_curl_maxstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func submitConcurrentWatch(cx ctlCtx, number int, wgDone *sync.WaitGroup, closeC
expectedLine := `"created":true}}`
_, lerr := proc.ExpectWithContext(context.TODO(), expect.ExpectedResponse{Value: expectedLine})
if lerr != nil {
return fmt.Errorf("%v %v (expected %q). Try EXPECT_DEBUG=TRUE", args, lerr, expectedLine)
return fmt.Errorf("%v %w (expected %q). Try EXPECT_DEBUG=TRUE", args, lerr, expectedLine)
}

wgSchedule.Done()
Expand All @@ -182,7 +182,7 @@ func submitConcurrentWatch(cx ctlCtx, number int, wgDone *sync.WaitGroup, closeC
case <-closeCh:
default:
// perr could be nil.
return fmt.Errorf("unexpected connection close before server closes: %v", perr)
return fmt.Errorf("unexpected connection close before server closes: %w", perr)
}
return nil
}
Expand Down Expand Up @@ -225,19 +225,19 @@ func submitRangeAfterConcurrentWatch(cx ctlCtx, expectedValue string) {
func setRLimit(nofile uint64) (func() error, error) {
var rLimit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
return nil, fmt.Errorf("failed to get open file limit, error: %v", err)
return nil, fmt.Errorf("failed to get open file limit, error: %w", err)
}

var wLimit syscall.Rlimit
wLimit.Max = nofile
wLimit.Cur = nofile
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &wLimit); err != nil {
return nil, fmt.Errorf("failed to set max open file limit, %v", err)
return nil, fmt.Errorf("failed to set max open file limit, %w", err)
}

return func() error {
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
return fmt.Errorf("failed reset max open file limit, %v", err)
return fmt.Errorf("failed reset max open file limit, %w", err)
}
return nil
}, nil
Expand Down
14 changes: 7 additions & 7 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
proc, err := NewEtcdProcess(t, etcdCfgs[i])
if err != nil {
epc.Close()
return nil, fmt.Errorf("cannot configure: %v", err)
return nil, fmt.Errorf("cannot configure: %w", err)
}
epc.Procs[i] = proc
}
Expand All @@ -449,11 +449,11 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
func StartEtcdProcessCluster(ctx context.Context, t testing.TB, epc *EtcdProcessCluster, cfg *EtcdProcessClusterConfig) (*EtcdProcessCluster, error) {
if cfg.RollingStart {
if err := epc.RollingStart(ctx); err != nil {
return nil, fmt.Errorf("cannot rolling-start: %v", err)
return nil, fmt.Errorf("cannot rolling-start: %w", err)
}
} else {
if err := epc.Start(ctx); err != nil {
return nil, fmt.Errorf("cannot start: %v", err)
return nil, fmt.Errorf("cannot start: %w", err)
}
}

Expand All @@ -465,7 +465,7 @@ func StartEtcdProcessCluster(ctx context.Context, t testing.TB, epc *EtcdProcess
}
if cfg.InitialLeaderIndex >= 0 {
if err := epc.MoveLeader(ctx, t, cfg.InitialLeaderIndex); err != nil {
return nil, fmt.Errorf("failed to move leader: %v", err)
return nil, fmt.Errorf("failed to move leader: %w", err)
}
}
return epc, nil
Expand Down Expand Up @@ -864,7 +864,7 @@ func (epc *EtcdProcessCluster) StartNewProcFromConfig(ctx context.Context, tb te
proc, err := NewEtcdProcess(tb, serverCfg)
if err != nil {
epc.Close()
return fmt.Errorf("cannot configure: %v", err)
return fmt.Errorf("cannot configure: %w", err)
}

epc.Procs = append(epc.Procs, proc)
Expand Down Expand Up @@ -947,7 +947,7 @@ func (epc *EtcdProcessCluster) Stop() (err error) {
}
if curErr := p.Stop(); curErr != nil {
if err != nil {
err = fmt.Errorf("%v; %v", err, curErr)
err = fmt.Errorf("%w; %w", err, curErr)
} else {
err = curErr
}
Expand All @@ -969,7 +969,7 @@ func (epc *EtcdProcessCluster) ConcurrentStop() (err error) {
for range epc.Procs {
if curErr := <-errCh; curErr != nil {
if err != nil {
err = fmt.Errorf("%v; %v", err, curErr)
err = fmt.Errorf("%w; %w", err, curErr)
} else {
err = curErr
}
Expand Down
3 changes: 2 additions & 1 deletion tests/framework/e2e/etcdctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package e2e
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"strconv"
Expand Down Expand Up @@ -252,7 +253,7 @@ func AddTxnResponse(resp *clientv3.TxnResponse, jsonData string) {
jd := json.NewDecoder(strings.NewReader(jsonData))
for {
t, e := jd.Token()
if e == io.EOF {
if errors.Is(e, io.EOF) {
break
}
if t == "response_range" {
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func SpawnWithExpectLines(ctx context.Context, args []string, envVars map[string
l, lerr := proc.ExpectWithContext(ctx, txt)
if lerr != nil {
proc.Close()
return nil, fmt.Errorf("%v %v (expected %q, got %q). Try EXPECT_DEBUG=TRUE", args, lerr, txt.Value, lines)
return nil, fmt.Errorf("%v %w (expected %q, got %q). Try EXPECT_DEBUG=TRUE", args, lerr, txt.Value, lines)
}
lines = append(lines, l)
}
Expand Down
10 changes: 5 additions & 5 deletions tests/framework/integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,13 @@ func (m *Member) listenGRPC() error {
m.Logger.Info("LISTEN GRPC", zap.String("grpcAddr", grpcAddr), zap.String("m.Name", m.Name), zap.String("workdir", wd))
grpcListener, err := net.Listen(network, grpcAddr)
if err != nil {
return fmt.Errorf("listen failed on grpc socket %s (%v)", grpcAddr, err)
return fmt.Errorf("listen failed on grpc socket %s (%w)", grpcAddr, err)
}

addr := grpcListener.Addr().String()
_, port, err = net.SplitHostPort(addr)
if err != nil {
return fmt.Errorf("failed to parse grpc listen port from address %s (%v)", addr, err)
return fmt.Errorf("failed to parse grpc listen port from address %s (%w)", addr, err)
}
m.Port = port
m.GRPCURL = fmt.Sprintf("%s://%s", m.clientScheme(), addr)
Expand Down Expand Up @@ -830,7 +830,7 @@ func (m *Member) addBridge() (*bridge, error) {
m.Logger.Info("LISTEN BRIDGE", zap.String("grpc-address", bridgeAddr), zap.String("member", m.Name))
bridgeListener, err := transport.NewUnixListener(bridgeAddr)
if err != nil {
return nil, fmt.Errorf("listen failed on bridge socket %s (%v)", bridgeAddr, err)
return nil, fmt.Errorf("listen failed on bridge socket %s (%w)", bridgeAddr, err)
}
m.GRPCBridge = newBridge(dialer{network: network, addr: grpcAddr}, bridgeListener)

Expand Down Expand Up @@ -962,7 +962,7 @@ func (m *Member) Launch() error {
)
var err error
if m.Server, err = etcdserver.NewServer(m.ServerConfig); err != nil {
return fmt.Errorf("failed to initialize the etcd server: %v", err)
return fmt.Errorf("failed to initialize the etcd server: %w", err)
}
m.Server.SyncTicker = time.NewTicker(500 * time.Millisecond)
m.Server.Start()
Expand Down Expand Up @@ -1568,7 +1568,7 @@ func (c *Cluster) GetLearnerMembers() ([]*pb.Member, error) {
cli := c.Client(0)
resp, err := cli.MemberList(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to list member %v", err)
return nil, fmt.Errorf("failed to list member %w", err)
}
var learners []*pb.Member
for _, m := range resp.Members {
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func tlsInfo(t testing.TB, cfg config.TLSConfig) (*transport.TLSInfo, error) {
case config.AutoTLS:
tls, err := transport.SelfCert(zap.NewNop(), t.TempDir(), []string{"localhost"}, 1)
if err != nil {
return nil, fmt.Errorf("failed to generate cert: %s", err)
return nil, fmt.Errorf("failed to generate cert: %w", err)
}
return &tls, nil
case config.ManualTLS:
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/clientv3/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func TestKVCompact(t *testing.T) {
if !wr.Canceled {
t.Fatalf("expected canceled watcher on compacted revision, got %v", wr.Canceled)
}
if wr.Err() != rpctypes.ErrCompacted {
if !errors.Is(wr.Err(), rpctypes.ErrCompacted) {
t.Fatalf("watch response error expected %v, got %v", rpctypes.ErrCompacted, wr.Err())
}
wr, ok := <-wchan
Expand Down Expand Up @@ -750,7 +750,8 @@ func TestKVLargeRequests(t *testing.T) {
cli := clus.Client(0)
_, err := cli.Put(context.TODO(), "foo", strings.Repeat("a", test.valueSize))

if _, ok := err.(rpctypes.EtcdError); ok {
var etcdErr rpctypes.EtcdError
if errors.As(err, &etcdErr) {
if !errors.Is(err, test.expectError) {
t.Errorf("#%d: expected %v, got %v", i, test.expectError, err)
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/clientv3/lease/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,8 @@ func TestLeaseKeepAliveLoopExit(t *testing.T) {
cli.Close()

_, err = cli.KeepAlive(ctx, resp.ID)
if _, ok := err.(clientv3.ErrKeepAliveHalted); !ok {
var keepAliveHaltedErr clientv3.ErrKeepAliveHalted
if !errors.As(err, &keepAliveHaltedErr) {
t.Fatalf("expected %T, got %v(%T)", clientv3.ErrKeepAliveHalted{}, err, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/clientv3/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ func TestGetTokenWithoutAuth(t *testing.T) {
defer client.Close()
}

switch err {
case nil:
switch {
case err == nil:
t.Log("passes as expected")
case context.DeadlineExceeded:
case errors.Is(err, context.DeadlineExceeded):
t.Errorf("not expected result:%v with endpoint:%s", err, authapi.Endpoints())
default:
t.Errorf("other errors:%v", err)
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/clientv3/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func TestWatchResumeCompacted(t *testing.T) {
if wresp.Err() == nil {
continue
}
if wresp.Err() != rpctypes.ErrCompacted {
if !errors.Is(wresp.Err(), rpctypes.ErrCompacted) {
t.Fatalf("wresp.Err() expected %v, got %+v", rpctypes.ErrCompacted, wresp.Err())
}
break
Expand Down Expand Up @@ -519,7 +519,7 @@ func TestWatchCompactRevision(t *testing.T) {
if !ok {
t.Fatalf("expected wresp, but got closed channel")
}
if wresp.Err() != rpctypes.ErrCompacted {
if !errors.Is(wresp.Err(), rpctypes.ErrCompacted) {
t.Fatalf("wresp.Err() expected %v, but got %v", rpctypes.ErrCompacted, wresp.Err())
}
if !wresp.Canceled {
Expand Down Expand Up @@ -858,7 +858,7 @@ func TestWatchWithRequireLeader(t *testing.T) {
if !ok {
t.Fatalf("expected %v watch channel, got closed channel", rpctypes.ErrNoLeader)
}
if resp.Err() != rpctypes.ErrNoLeader {
if !errors.Is(resp.Err(), rpctypes.ErrNoLeader) {
t.Fatalf("expected %v watch response error, got %+v", rpctypes.ErrNoLeader, resp)
}
case <-time.After(integration2.RequestWaitTimeout):
Expand Down
Loading