Skip to content

Commit f96e399

Browse files
authored
Upgrade to golangci-lint v1.60.1 (#570)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
1 parent 463219e commit f96e399

File tree

7 files changed

+28
-20
lines changed

7 files changed

+28
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ check-protos: clean-protos protos ## Re-generates protos and git diffs them
8282
GOPATH=$(CURDIR)/.tools go install github.com/fatih/faillint@v1.13.0
8383

8484
.tools/bin/golangci-lint: .tools
85-
GOPATH=$(CURDIR)/.tools go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
85+
GOPATH=$(CURDIR)/.tools go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1
8686

8787
.tools/bin/protoc: .tools
8888
ifeq ("$(wildcard .tools/protoc/bin/protoc)","")

grpcutil/status_test.go

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
78
"testing"
@@ -26,10 +27,10 @@ func TestErrorToStatus(t *testing.T) {
2627
err: nil,
2728
},
2829
"a random error cannot be cast to status.Status": {
29-
err: fmt.Errorf(msgErr),
30+
err: errors.New(msgErr),
3031
},
3132
"a wrapped error of a random error cannot be cast to status.Status": {
32-
err: fmt.Errorf("wrapped: %w", fmt.Errorf(msgErr)),
33+
err: fmt.Errorf("wrapped: %w", errors.New(msgErr)),
3334
},
3435
"a gRPC error built by gogo/status can be cast to status.Status": {
3536
err: status.Error(codes.Internal, msgErr),
@@ -74,11 +75,11 @@ func TestErrorToStatusCode(t *testing.T) {
7475
expectedStatusCode: codes.OK,
7576
},
7677
"a non-gRPC error returns codes.Unknown": {
77-
err: fmt.Errorf(msgErr),
78+
err: errors.New(msgErr),
7879
expectedStatusCode: codes.Unknown,
7980
},
8081
"a wrapped non-gRPC error returns codes.Unknown": {
81-
err: fmt.Errorf("wrapped: %w", fmt.Errorf(msgErr)),
82+
err: fmt.Errorf("wrapped: %w", errors.New(msgErr)),
8283
expectedStatusCode: codes.Unknown,
8384
},
8485
"a gRPC error built by gogo/status returns its code": {
@@ -132,11 +133,11 @@ func TestIsCanceled(t *testing.T) {
132133
expectedOutcome: true,
133134
},
134135
"a random error returns false": {
135-
err: fmt.Errorf(msgErr),
136+
err: errors.New(msgErr),
136137
expectedOutcome: false,
137138
},
138139
"a wrapped random error returns false": {
139-
err: fmt.Errorf("wrapped: %w", fmt.Errorf(msgErr)),
140+
err: fmt.Errorf("wrapped: %w", errors.New(msgErr)),
140141
expectedOutcome: false,
141142
},
142143
"a gRPC error with code different from codes.Canceled returns false": {

httpgrpc/httpgrpc.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,23 @@ func FromHeader(hs http.Header) []*Header {
106106
return result
107107
}
108108

109-
// Errorf returns a HTTP gRPC error than is correctly forwarded over
109+
// Error returns a HTTP gRPC error that is correctly forwarded over
110110
// gRPC, and can eventually be converted back to a HTTP response with
111111
// HTTPResponseFromError.
112-
func Errorf(code int, tmpl string, args ...interface{}) error {
112+
func Error(code int, msg string) error {
113113
return ErrorFromHTTPResponse(&HTTPResponse{
114114
Code: int32(code),
115-
Body: []byte(fmt.Sprintf(tmpl, args...)),
115+
Body: []byte(msg),
116116
})
117117
}
118118

119+
// Errorf returns a HTTP gRPC error that is correctly forwarded over
120+
// gRPC, and can eventually be converted back to a HTTP response with
121+
// HTTPResponseFromError.
122+
func Errorf(code int, tmpl string, args ...interface{}) error {
123+
return Error(code, fmt.Sprintf(tmpl, args...))
124+
}
125+
119126
// ErrorFromHTTPResponse converts an HTTP response into a grpc error, and uses HTTP response body as an error message.
120127
// Note that if HTTP response body contains non-utf8 string, then returned error cannot be marshalled by protobuf.
121128
func ErrorFromHTTPResponse(resp *HTTPResponse) error {

httpgrpc/httpgrpc_test.go

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
78
"testing"
@@ -52,7 +53,7 @@ func TestErrorf(t *testing.T) {
5253
Code: int32(code),
5354
Body: []byte(errMsg),
5455
}
55-
err := Errorf(code, errMsg)
56+
err := Error(code, errMsg)
5657
stat, ok := status.FromError(err)
5758
require.True(t, ok)
5859
require.Equal(t, code, int(stat.Code()))
@@ -90,7 +91,7 @@ func TestHTTPResponseFromError(t *testing.T) {
9091
err: nil,
9192
},
9293
"a random error cannot be parsed to an HTTPResponse": {
93-
err: fmt.Errorf(msgErr),
94+
err: errors.New(msgErr),
9495
},
9596
"a gRPC error built by gogo/status cannot be parsed to an HTTPResponse": {
9697
err: status.Error(codes.Internal, msgErr),
@@ -99,11 +100,11 @@ func TestHTTPResponseFromError(t *testing.T) {
99100
err: grpcstatus.Error(codes.Internal, msgErr),
100101
},
101102
"a gRPC error built by httpgrpc can be parsed to an HTTPResponse": {
102-
err: Errorf(400, msgErr),
103+
err: Error(400, msgErr),
103104
expectedHTTPResponse: &HTTPResponse{Code: 400, Body: []byte(msgErr)},
104105
},
105106
"a wrapped gRPC error built by httpgrpc can be parsed to an HTTPResponse": {
106-
err: fmt.Errorf("wrapped: %w", Errorf(400, msgErr)),
107+
err: fmt.Errorf("wrapped: %w", Error(400, msgErr)),
107108
expectedHTTPResponse: &HTTPResponse{Code: 400, Body: []byte(msgErr)},
108109
},
109110
}

middleware/grpc_instrumentation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ func TestInstrumentationLabel_ErrorToStatusCode(t *testing.T) {
219219
expectedGRPCStatueCodes: codes.FailedPrecondition,
220220
},
221221
"a gRPC error with status codes.Canceled returns codes.Canceled": {
222-
err: status.Errorf(codes.Canceled, context.Canceled.Error()),
222+
err: status.Error(codes.Canceled, context.Canceled.Error()),
223223
expectedGRPCStatueCodes: codes.Canceled,
224224
},
225225
"a wrapped gRPC error with status codes.Canceled returns codes.Canceled": {
226-
err: fmt.Errorf("wrapped: %w", status.Errorf(codes.Canceled, context.Canceled.Error())),
226+
err: fmt.Errorf("wrapped: %w", status.Error(codes.Canceled, context.Canceled.Error())),
227227
expectedGRPCStatueCodes: codes.Canceled,
228228
},
229229
"context.Canceled returns codes.Canceled": {
@@ -239,7 +239,7 @@ func TestInstrumentationLabel_ErrorToStatusCode(t *testing.T) {
239239
expectedGRPCStatueCodes: codes.Unknown,
240240
},
241241
"a non-gRPC error returns codes.Unknown": {
242-
err: fmt.Errorf(errMsg),
242+
err: errors.New(errMsg),
243243
expectedGRPCStatueCodes: codes.Unknown,
244244
},
245245
}

ring/replication_set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func DoUntilQuorumWithoutSuccessfulContextCancellation[T any](ctx context.Contex
316316
ext.Error.Set(cfg.Logger.Span, true)
317317
}
318318

319-
contextTracker.cancelAllContexts(cancellation.NewErrorf(cause))
319+
contextTracker.cancelAllContexts(cancellation.NewError(errors.New(cause)))
320320
cleanupResultsAlreadyReceived()
321321
return nil, err
322322
}

server/server_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"os"
1919
"os/exec"
2020
"path/filepath"
21-
"strconv"
2221
"testing"
2322
"time"
2423

@@ -48,7 +47,7 @@ func (f FakeServer) FailWithError(_ context.Context, _ *protobuf.Empty) (*protob
4847
}
4948

5049
func (f FakeServer) FailWithHTTPError(_ context.Context, req *FailWithHTTPErrorRequest) (*protobuf.Empty, error) {
51-
return nil, httpgrpc.Errorf(int(req.Code), strconv.Itoa(int(req.Code)))
50+
return nil, httpgrpc.Errorf(int(req.Code), "%d", req.Code)
5251
}
5352

5453
func (f FakeServer) Succeed(_ context.Context, _ *protobuf.Empty) (*protobuf.Empty, error) {

0 commit comments

Comments
 (0)