Skip to content

Commit dcb46e2

Browse files
committed
enable errorlint
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 2d2c090 commit dcb46e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+177
-190
lines changed

.golangci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ run:
44
linters:
55
disable-all: true
66
enable:
7-
- misspell
7+
- errorlint
88
- gofmt
99
- goimports
10+
- govet
1011
- ineffassign
12+
- misspell
1113
- revive
1214
- unconvert
13-
- unused
14-
- govet
15-
15+
- unused

agent/agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package agent
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"math/rand"
89
"reflect"
@@ -517,7 +518,7 @@ func (a *Agent) UpdateTaskStatus(ctx context.Context, taskID string, status *api
517518
go func() {
518519
err := session.sendTaskStatus(ctx, taskID, status)
519520
if err != nil {
520-
if err == errTaskUnknown {
521+
if errors.Is(err, errTaskUnknown) {
521522
err = nil // dispatcher no longer cares about this task.
522523
} else {
523524
log.G(ctx).WithError(err).Error("closing session after fatal error")

agent/csi/plugin/manager.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package plugin
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"sync"
78

@@ -57,7 +58,7 @@ func (pm *pluginManager) Get(name string) (NodePlugin, error) {
5758

5859
plugin, err := pm.getPlugin(name)
5960
if err != nil {
60-
return nil, fmt.Errorf("cannot get plugin %v: %v", name, err)
61+
return nil, fmt.Errorf("cannot get plugin %v: %w", name, err)
6162
}
6263

6364
return plugin, nil
@@ -110,7 +111,7 @@ func (pm *pluginManager) getPlugin(name string) (NodePlugin, error) {
110111

111112
pa, ok := pc.(plugin.AddrPlugin)
112113
if !ok {
113-
return nil, fmt.Errorf("plugin does not implement PluginAddr interface")
114+
return nil, errors.New("plugin does not implement PluginAddr interface")
114115
}
115116

116117
p := pm.newNodePluginFunc(name, pa, pm.secrets)

agent/csi/volumes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package csi
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"sync"
78
"time"
@@ -131,7 +132,7 @@ func (r *volumes) Get(volumeID string) (string, error) {
131132
if vs, ok := r.volumes[volumeID]; ok {
132133
if vs.remove {
133134
// TODO(dperny): use a structured error
134-
return "", fmt.Errorf("volume being removed")
135+
return "", errors.New("volume being removed")
135136
}
136137

137138
if p, err := r.plugins.Get(vs.volume.Driver.Name); err == nil {

agent/exec/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ func Do(ctx context.Context, task *api.Task, ctlr Controller) (*api.TaskStatus,
308308
// the following states may proceed past desired state.
309309
switch status.State {
310310
case api.TaskStatePreparing:
311-
if err := ctlr.Prepare(ctx); err != nil && err != ErrTaskPrepared {
311+
if err := ctlr.Prepare(ctx); err != nil && !errors.Is(err, ErrTaskPrepared) {
312312
return fatal(err)
313313
}
314314

315315
return transition(api.TaskStateReady, "prepared")
316316
case api.TaskStateStarting:
317-
if err := ctlr.Start(ctx); err != nil && err != ErrTaskStarted {
317+
if err := ctlr.Start(ctx); err != nil && !errors.Is(err, ErrTaskStarted) {
318318
return fatal(err)
319319
}
320320

agent/task.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package agent
22

33
import (
44
"context"
5+
"errors"
56
"sync"
67
"time"
78

@@ -160,20 +161,20 @@ func (tm *taskManager) run(ctx context.Context) {
160161
default:
161162
}
162163

163-
switch err {
164-
case exec.ErrTaskNoop:
164+
switch {
165+
case errors.Is(err, exec.ErrTaskNoop):
165166
if !updated {
166167
continue // wait till getting pumped via update.
167168
}
168-
case exec.ErrTaskRetry:
169+
case errors.Is(err, exec.ErrTaskRetry):
169170
// TODO(stevvooe): Add exponential backoff with random jitter
170171
// here. For now, this backoff is enough to keep the task
171172
// manager from running away with the CPU.
172173
time.AfterFunc(time.Second, func() {
173174
errs <- nil // repump this branch, with no err
174175
})
175176
continue
176-
case nil, context.Canceled, context.DeadlineExceeded:
177+
case err == nil, errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
177178
// no log in this case
178179
default:
179180
log.G(ctx).WithError(err).Error("task operation failed")

agent/worker.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package agent
22

33
import (
44
"context"
5+
"errors"
56
"sync"
67

78
"github.com/moby/swarmkit/v2/agent/exec"
@@ -239,15 +240,15 @@ func reconcileTaskState(ctx context.Context, w *worker, assignments []*api.Assig
239240
}
240241

241242
if mgr, ok := w.taskManagers[task.ID]; ok {
242-
if err := mgr.Update(ctx, task); err != nil && err != ErrClosed {
243+
if err := mgr.Update(ctx, task); err != nil && !errors.Is(err, ErrClosed) {
243244
log.G(ctx).WithError(err).Error("failed updating assigned task")
244245
}
245246
} else {
246247
// we may have still seen the task, let's grab the status from
247248
// storage and replace it with our status, if we have it.
248249
status, err := GetTaskStatus(tx, task.ID)
249250
if err != nil {
250-
if err != errTaskUnknown {
251+
if !errors.Is(err, errTaskUnknown) {
251252
return err
252253
}
253254

@@ -569,7 +570,7 @@ func (w *worker) updateTaskStatus(ctx context.Context, tx *bolt.Tx, taskID strin
569570
// dance of too-tightly-coupled concurrent parts, fixing tht race is
570571
// fraught with hazards. instead, we'll recognize that it can occur,
571572
// log the error, and then ignore it.
572-
if err == errTaskUnknown {
573+
if errors.Is(err, errTaskUnknown) {
573574
// log at info level. debug logging in docker is already really
574575
// verbose, so many people disable it. the race that causes this
575576
// behavior should be very rare, but if it occurs, we should know

api/genericresource/resource_management.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package genericresource
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/moby/swarmkit/v2/api"
@@ -15,7 +16,7 @@ func Claim(nodeAvailableResources, taskAssigned *[]*api.GenericResource,
1516
for _, res := range taskReservations {
1617
tr := res.GetDiscreteResourceSpec()
1718
if tr == nil {
18-
return fmt.Errorf("task should only hold Discrete type")
19+
return errors.New("task should only hold Discrete type")
1920
}
2021

2122
// Select the resources
@@ -86,7 +87,7 @@ func Reclaim(nodeAvailableResources *[]*api.GenericResource, taskAssigned, nodeR
8687
func reclaimResources(nodeAvailableResources *[]*api.GenericResource, taskAssigned []*api.GenericResource) error {
8788
// The node could have been updated
8889
if nodeAvailableResources == nil {
89-
return fmt.Errorf("node no longer has any resources")
90+
return errors.New("node no longer has any resources")
9091
}
9192

9293
for _, res := range taskAssigned {

api/genericresource/validate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package genericresource
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/moby/swarmkit/v2/api"
@@ -24,7 +25,7 @@ func ValidateTask(resources *api.Resources) error {
2425
func HasEnough(nodeRes []*api.GenericResource, taskRes *api.GenericResource) (bool, error) {
2526
t := taskRes.GetDiscreteResourceSpec()
2627
if t == nil {
27-
return false, fmt.Errorf("task should only hold Discrete type")
28+
return false, errors.New("task should only hold Discrete type")
2829
}
2930

3031
if nodeRes == nil {

api/storeobject.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func customIndexer(kind string, annotations *Annotations) (bool, [][]byte, error
7575

7676
func fromArgs(args ...interface{}) ([]byte, error) {
7777
if len(args) != 1 {
78-
return nil, fmt.Errorf("must provide only a single argument")
78+
return nil, errors.New("must provide only a single argument")
7979
}
8080
arg, ok := args[0].(string)
8181
if !ok {

0 commit comments

Comments
 (0)