Skip to content

Commit 1515a7a

Browse files
committed
lint: errorlint
1 parent b36e67a commit 1515a7a

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

backend/redis/events_future.go

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"strconv"
78
"time"
@@ -14,7 +15,7 @@ func scheduleFutureEvents(ctx context.Context, rb *redisBackend) error {
1415
nowStr := strconv.FormatInt(now, 10)
1516
if _, err := futureEventsCmd.Run(ctx, rb.rdb, []string{
1617
rb.keys.futureEventsKey(),
17-
}, nowStr, rb.keys.prefix).Result(); err != nil && err != redis.Nil {
18+
}, nowStr, rb.keys.prefix).Result(); err != nil && !errors.Is(err, redis.Nil) {
1819
return fmt.Errorf("checking future events: %w", err)
1920
}
2021

backend/redis/instance.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package redis
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"time"
89

@@ -63,10 +64,10 @@ func (rb *redisBackend) CreateWorkflowInstance(ctx context.Context, instance *wo
6364
payloadData,
6465
time.Now().UTC().UnixNano(),
6566
).Result()
66-
6767
if err != nil {
68-
if _, ok := err.(redis.Error); ok {
69-
if err.Error() == "ERR InstanceAlreadyExists" {
68+
var redisErr redis.Error
69+
if errors.As(err, &redisErr) {
70+
if redisErr.Error() == "ERR InstanceAlreadyExists" {
7071
return backend.ErrInstanceAlreadyExists
7172
}
7273
}
@@ -194,7 +195,7 @@ func readInstanceP(ctx context.Context, p redis.Pipeliner, instanceKey string) *
194195
func readInstancePipelineCmd(cmd *redis.StringCmd) (*instanceState, error) {
195196
val, err := cmd.Result()
196197
if err != nil {
197-
if err == redis.Nil {
198+
if errors.Is(err, redis.Nil) {
198199
return nil, backend.ErrInstanceNotFound
199200
}
200201

@@ -212,7 +213,7 @@ func readInstancePipelineCmd(cmd *redis.StringCmd) (*instanceState, error) {
212213
func (rb *redisBackend) readActiveInstanceExecution(ctx context.Context, instanceID string) (*core.WorkflowInstance, error) {
213214
val, err := rb.rdb.Get(ctx, rb.keys.activeInstanceExecutionKey(instanceID)).Result()
214215
if err != nil {
215-
if err == redis.Nil {
216+
if errors.Is(err, redis.Nil) {
216217
return nil, nil
217218
}
218219

backend/redis/queue.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package redis
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"strings"
89
"time"
@@ -86,7 +87,7 @@ func (q *taskQueue[T]) Prepare(ctx context.Context, rdb redis.UniversalClient, q
8687
}
8788

8889
_, err := prepareCmd.Run(ctx, rdb, keys, q.groupName).Result()
89-
if err != nil && err != redis.Nil {
90+
if err != nil && !errors.Is(err, redis.Nil) {
9091
return fmt.Errorf("preparing queues: %w", err)
9192
}
9293

@@ -164,11 +165,11 @@ func (q *taskQueue[T]) Dequeue(ctx context.Context, rdb redis.UniversalClient, q
164165
Count: 1,
165166
Block: timeout,
166167
}).Result()
167-
if err != nil && err != redis.Nil {
168+
if err != nil && !errors.Is(err, redis.Nil) {
168169
return nil, fmt.Errorf("dequeueing task: %w", err)
169170
}
170171

171-
if len(ids) == 0 || len(ids[0].Messages) == 0 || err == redis.Nil {
172+
if len(ids) == 0 || len(ids[0].Messages) == 0 || errors.Is(err, redis.Nil) {
172173
return nil, nil
173174
}
174175

@@ -186,7 +187,7 @@ func (q *taskQueue[T]) Extend(ctx context.Context, p redis.Pipeliner, queue work
186187
Messages: []string{taskID},
187188
MinIdle: 0, // Always claim this message
188189
}).Result()
189-
if err != nil && err != redis.Nil {
190+
if err != nil && !errors.Is(err, redis.Nil) {
190191
return fmt.Errorf("extending lease: %w", err)
191192
}
192193

@@ -198,7 +199,7 @@ func (q *taskQueue[T]) Complete(ctx context.Context, p redis.Pipeliner, queue wo
198199
q.Keys(queue).SetKey,
199200
q.Keys(queue).StreamKey,
200201
}, taskID, q.groupName)
201-
if err := cmd.Err(); err != nil && err != redis.Nil {
202+
if err := cmd.Err(); err != nil && !errors.Is(err, redis.Nil) {
202203
return nil, fmt.Errorf("completing task: %w", err)
203204
}
204205

@@ -207,7 +208,7 @@ func (q *taskQueue[T]) Complete(ctx context.Context, p redis.Pipeliner, queue wo
207208

208209
func (q *taskQueue[T]) Data(ctx context.Context, p redis.Pipeliner, queue workflow.Queue, taskID string) (*TaskItem[T], error) {
209210
msg, err := p.XRange(ctx, q.Keys(queue).StreamKey, taskID, taskID).Result()
210-
if err != nil && err != redis.Nil {
211+
if err != nil && !errors.Is(err, redis.Nil) {
211212
return nil, fmt.Errorf("finding task: %w", err)
212213
}
213214

@@ -230,7 +231,7 @@ func (q *taskQueue[T]) recover(ctx context.Context, rdb redis.UniversalClient, q
230231
"0",
231232
).Slice()
232233
if err != nil {
233-
if err == redis.Nil {
234+
if errors.Is(err, redis.Nil) {
234235
return nil, nil
235236
}
236237

0 commit comments

Comments
 (0)