Skip to content

Commit a4a8d07

Browse files
authored
chore: enable errorlint (#774)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent fcf9bb9 commit a4a8d07

File tree

13 files changed

+40
-21
lines changed

13 files changed

+40
-21
lines changed

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ run:
77
linters:
88
enable:
99
- errcheck
10+
- errorlint
1011
- misspell
1112

1213
settings:
@@ -29,3 +30,9 @@ formatters:
2930
settings:
3031
gofumpt:
3132
extra-rules: true
33+
34+
issues:
35+
# Maximum issues count per one linter.
36+
max-issues-per-linter: 0
37+
# Maximum count of issues with the same text.
38+
max-same-issues: 0

interceptors/client.go

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

88
import (
99
"context"
10+
"errors"
1011
"io"
1112
"time"
1213

@@ -68,7 +69,7 @@ func (s *monitoredClientStream) RecvMsg(m any) error {
6869
return nil
6970
}
7071
var postErr error
71-
if err != io.EOF {
72+
if !errors.Is(err, io.EOF) {
7273
postErr = err
7374
}
7475
s.reporter.PostCall(postErr, time.Since(s.startTime))

interceptors/client_test.go

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

66
import (
77
"context"
8+
"errors"
89
"io"
910
"net"
1011
"sync"
@@ -249,7 +250,7 @@ func (s *ClientInterceptorTestSuite) TestListReporting() {
249250
count := 0
250251
for {
251252
_, err := ss.Recv()
252-
if err == io.EOF {
253+
if errors.Is(err, io.EOF) {
253254
break
254255
}
255256
require.NoError(s.T(), err, "reading pingList shouldn't fail")
@@ -305,7 +306,7 @@ func (s *ClientInterceptorTestSuite) TestBiStreamingReporting() {
305306
for s.ctx.Err() == nil {
306307

307308
_, err := ss.Recv()
308-
if err == io.EOF {
309+
if errors.Is(err, io.EOF) {
309310
break
310311
}
311312
if !s.Assert().NoError(err, "reading pingStream shouldn't fail") {

interceptors/logging/interceptors.go

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

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"io"
1011
"time"
@@ -31,7 +32,7 @@ func (c *reporter) PostCall(err error, duration time.Duration) {
3132
if !has(c.opts.loggableEvents, FinishCall) {
3233
return
3334
}
34-
if err == io.EOF {
35+
if errors.Is(err, io.EOF) {
3536
err = nil
3637
}
3738

interceptors/logging/interceptors_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"context"
99
"encoding/json"
10+
"errors"
1011
"fmt"
1112
"io"
1213
"runtime"
@@ -283,7 +284,7 @@ func (s *loggingClientServerSuite) TestPingList() {
283284
require.NoError(s.T(), err, "should not fail on establishing the stream")
284285
for {
285286
_, err := stream.Recv()
286-
if err == io.EOF {
287+
if errors.Is(err, io.EOF) {
287288
break
288289
}
289290
require.NoError(s.T(), err, "reading stream should not fail")
@@ -468,7 +469,7 @@ func (s *loggingCustomDurationSuite) TestPingList_HasOverriddenDuration() {
468469
require.NoError(s.T(), err, "should not fail on establishing the stream")
469470
for {
470471
_, err := stream.Recv()
471-
if err == io.EOF {
472+
if errors.Is(err, io.EOF) {
472473
break
473474
}
474475
require.NoError(s.T(), err, "reading stream should not fail")
@@ -754,7 +755,7 @@ func (s *loggingCustomGrpcLogFieldsSuite) TestCustomGrpcLogFieldsWithPingList()
754755
require.NoError(s.T(), err, "should not fail on establishing the stream")
755756
for {
756757
_, err := stream.Recv()
757-
if err == io.EOF {
758+
if errors.Is(err, io.EOF) {
758759
break
759760
}
760761
require.NoError(s.T(), err, "reading stream should not fail")

interceptors/retry/examples_test.go

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

66
import (
77
"context"
8+
"errors"
89
"io"
910
"time"
1011

@@ -58,7 +59,7 @@ func Example_simpleCall() {
5859

5960
for {
6061
_, err := stream.Recv() // retries happen here
61-
if err == io.EOF {
62+
if errors.Is(err, io.EOF) {
6263
break
6364
} else if err != nil {
6465
return

interceptors/retry/retry.go

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

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"io"
1011
"sync"
@@ -213,7 +214,7 @@ func (s *serverStreamingRetryingStream) RecvMsg(m any) error {
213214

214215
func (s *serverStreamingRetryingStream) receiveMsgAndIndicateRetry(m any) (bool, error) {
215216
err := s.getStream().RecvMsg(m)
216-
if err == nil || err == io.EOF {
217+
if err == nil || errors.Is(err, io.EOF) {
217218
return false, err
218219
}
219220
if isContextError(err) {
@@ -308,10 +309,10 @@ func perStreamContext(parentCtx context.Context, callOpts *options, attempt uint
308309
}
309310

310311
func contextErrToGrpcErr(err error) error {
311-
switch err {
312-
case context.DeadlineExceeded:
312+
switch {
313+
case errors.Is(err, context.DeadlineExceeded):
313314
return status.Error(codes.DeadlineExceeded, err.Error())
314-
case context.Canceled:
315+
case errors.Is(err, context.Canceled):
315316
return status.Error(codes.Canceled, err.Error())
316317
default:
317318
return status.Error(codes.Unknown, err.Error())

interceptors/retry/retry_test.go

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

66
import (
77
"context"
8+
"errors"
89
"io"
910
"strconv"
1011
"strings"
@@ -299,7 +300,7 @@ func (s *RetrySuite) assertPingListWasCorrect(stream testpb.TestService_PingList
299300
count := 0
300301
for {
301302
pong, err := stream.Recv()
302-
if err == io.EOF {
303+
if errors.Is(err, io.EOF) {
303304
break
304305
}
305306
require.NoError(s.T(), err, "no errors during receive on client side")

interceptors/server_test.go

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

66
import (
77
"context"
8+
"errors"
89
"io"
910
"net"
1011
"sync"
@@ -111,7 +112,7 @@ func (s *ServerInterceptorTestSuite) TestStreamingReports() {
111112
count := 0
112113
for {
113114
_, err := ss.Recv()
114-
if err == io.EOF {
115+
if errors.Is(err, io.EOF) {
115116
break
116117
}
117118
require.NoError(s.T(), err, "reading pingList shouldn't fail")
@@ -153,7 +154,7 @@ func (s *ServerInterceptorTestSuite) TestBiStreamingReporting() {
153154
for s.ctx.Err() == nil {
154155

155156
_, err := ss.Recv()
156-
if err == io.EOF {
157+
if errors.Is(err, io.EOF) {
157158
break
158159
}
159160
require.NoError(s.T(), err, "reading pingStream shouldn't fail")

interceptors/validator/interceptors_test.go

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

66
import (
77
"context"
8+
"errors"
89
"io"
910
"testing"
1011

@@ -38,7 +39,7 @@ func (s *ValidatorTestSuite) TestValidPasses_ServerStream() {
3839
require.NoError(s.T(), err, "no error on stream establishment expected")
3940
for {
4041
_, err := stream.Recv()
41-
if err == io.EOF {
42+
if errors.Is(err, io.EOF) {
4243
break
4344
}
4445
assert.NoError(s.T(), err, "no error on messages sent occurred")

0 commit comments

Comments
 (0)