Skip to content

Commit 95b001d

Browse files
authored
Merge pull request #14 from aserto-dev/update-deps
Update deps
2 parents d2a19aa + d207403 commit 95b001d

9 files changed

Lines changed: 131 additions & 160 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: ci
23

34
on:
@@ -13,16 +14,16 @@ on:
1314
branches:
1415
- main
1516
- release-*
16-
env:
17+
env:
1718
PRE_RELEASE: ${{ github.ref == 'refs/heads/main' && 'development' || '' }}
18-
GO_VERSION: "1.22"
19-
GO_LANGCI_LINT_VERSION: "v1.56.2"
19+
GO_VERSION: "1.23"
20+
GO_LANGCI_LINT_VERSION: "v1.61.0"
2021
GO_TESTSUM_VERSION: "1.11.0"
2122

2223
jobs:
2324
test:
2425
runs-on: ubuntu-latest
25-
steps:
26+
steps:
2627
- uses: actions/checkout@v4
2728
with:
2829
fetch-depth: 0
@@ -32,7 +33,7 @@ jobs:
3233
go-version: ${{ env.GO_VERSION }}
3334
-
3435
name: Lint
35-
uses: golangci/golangci-lint-action@v4
36+
uses: golangci/golangci-lint-action@v6
3637
with:
3738
version: ${{ env.GO_LANGCI_LINT_VERSION }}
3839
args: --timeout=30m

.golangci.yaml

Lines changed: 71 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@
33
# https://github.com/golangci/golangci/wiki/Configuration
44

55
linters-settings:
6-
depguard:
7-
list-type: blacklist
8-
packages:
9-
# logging is allowed only by zerolog
10-
- github.com/sirupsen/logrus
11-
packages-with-error-message:
12-
- github.com/sirupsen/logrus: "logging is allowed only by zerolog"
13-
dupl:
14-
threshold: 100
156
funlen:
167
lines: 100
178
statements: 80
18-
gci:
19-
local-prefixes: github.com/golangci/golangci-lint
209
goconst:
2110
min-len: 2
2211
min-occurrences: 2
@@ -28,133 +17,134 @@ linters-settings:
2817
- performance
2918
- style
3019
disabled-checks:
31-
- dupImport # https://github.com/go-critic/go-critic/issues/845
20+
- dupImport # https://github.com/go-critic/go-critic/issues/845
3221
- ifElseChain
3322
- octalLiteral
3423
- whyNoLint
3524
- wrapperFunc
3625
gocyclo:
37-
min-complexity: 20
26+
min-complexity: 18
3827
goimports:
3928
local-prefixes: github.com/golangci/golangci-lint
40-
golint:
41-
min-confidence: 0
42-
gomnd:
43-
settings:
44-
mnd:
45-
# don't include the "operation" and "assign"
46-
checks:
47-
- argument
48-
- case
49-
- condition
50-
- return
29+
mnd:
30+
checks:
31+
- argument
32+
- case
33+
- condition
34+
- return
5135
govet:
52-
check-shadowing: true
36+
shadow: true
5337
settings:
5438
printf:
5539
funcs:
5640
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
5741
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
5842
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
5943
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
60-
maligned:
61-
suggest-new: true
44+
lll:
45+
line-length: 140
6246
misspell:
6347
locale: US
6448
nolintlint:
65-
allow-unused: false # report any unused nolint directives
66-
require-explanation: false # don't require an explanation for nolint directives
67-
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
49+
allow-unused: false # report any unused nolint directives
50+
require-explanation: false # don't require an explanation for nolint directives
51+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
6852

6953
linters:
7054
# please, do not use `enable-all`: it's deprecated and will be removed soon.
7155
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
72-
disable-all: true
56+
disable-all: false
7357
enable:
58+
- asasalint
7459
- asciicheck
60+
- bidichk
7561
- bodyclose
62+
- canonicalheader
63+
- containedctx
64+
- contextcheck
65+
- copyloopvar
66+
- cyclop
67+
- decorder
7668
- dogsled
77-
- errcheck
78-
- exportloopref
69+
- dupword
70+
- durationcheck
71+
- err113
72+
- errchkjson
73+
- errname
74+
- errorlint
7975
- exhaustive
76+
- fatcontext
77+
- forcetypeassert
8078
- funlen
79+
- gocheckcompilerdirectives
80+
- gochecknoinits
81+
- gochecknoglobals
8182
- gochecknoinits
83+
- gocognit
8284
- goconst
8385
- gocritic
8486
- gocyclo
8587
- godot
86-
# - goerr113 # temporary disabled
8788
- gofmt
8889
- goimports
8990
- goprintffuncname
9091
- gosec
91-
- gosimple
92-
- govet
93-
- ineffassign
92+
- gosmopolitan
93+
- grouper
94+
- importas
95+
- inamedparam
96+
- interfacebloat
97+
- intrange
98+
- lll
99+
- makezero
100+
- mirror
94101
- misspell
102+
- mnd
103+
- musttag
95104
- nakedret
105+
- nestif
106+
- nilerr
107+
- nilnil
96108
- noctx
97-
# - rowserrcheck # disable https://github.com/golangci/golangci-lint/issues/2649.
98-
- staticcheck
109+
- nolintlint
110+
- nonamedreturns
111+
- perfsprint
112+
- prealloc
113+
- predeclared
114+
- reassign
115+
- rowserrcheck
99116
- stylecheck
100117
- testpackage
101-
- typecheck
102118
- unconvert
103119
- unparam
104-
- unused
120+
- usestdlibvars
121+
- wastedassign
122+
- whitespace
123+
- zerologlint
105124

106-
# don't enable:
125+
# don't enable:
107126
# - depguard
108127
# - dupl
128+
# - exhaustruct
129+
# - gci
130+
# - ginkgolinter
109131
# - gochecknoglobals
110132
# - gocognit
111133
# - godox
112-
# - gomnd
134+
# - gofumpt
135+
# - gomoddirectives
136+
# - ireturn
113137
# - lll
114-
# - nestif
138+
# - nlreturn
115139
# - nolintlint # conflict with 1.19 gofmt changes
140+
# - protogetter
116141
# - prealloc
117142
# - revive
118143
# - wsl
119-
# - whitespace
144+
# - wrapcheck
120145

121146
issues:
122-
# List of regexps of issue texts to exclude, empty list by default.
123-
# But independently from this option we use default exclude patterns,
124-
# it can be disabled by `exclude-use-default: false`. To list all
125-
# excluded by default patterns execute `golangci-lint run --help`
126-
exclude:
127-
- declaration of "(err|ctx)" shadows declaration at
128-
- shadow of imported from 'github.com/stretchr/testify/assert' package 'assert'
129-
# Excluding configuration per-path, per-linter, per-text and per-source
130147
exclude-rules:
131-
- path: _test\.go
132-
linters:
133-
- gomnd
134-
# https://github.com/go-critic/go-critic/issues/926
135-
- text: "unnecessaryDefer:"
136-
linters:
137-
- gocritic
138148
- text: "unnamedResult:"
139149
linters:
140-
- gocritic
141-
- path: \.resolvers\.go
142-
text: "typeDefFirst:"
143-
linters:
144-
- gocritic
145-
- path: \.resolvers\.go
146-
text: "paramTypeCombine:"
147-
linters:
148-
- gocritic
149-
- path: \.resolvers\.go
150-
text: "hugeParam:"
151-
linters:
152-
- gocritic
153-
- text: "G404"
154-
linters:
155-
- gosec
156-
157-
run:
158-
timeout: 5m
159-
skip-dirs:
160-
- aserto/directory
150+
- gocritic

context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// that can also encapsulate a context.
1111
type ContextError struct {
1212
Err error
13-
Ctx context.Context
13+
Ctx context.Context //nolint:containedctx
1414
}
1515

1616
func WithContext(err error, ctx context.Context) *ContextError {

custom_error_handler.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ const (
1515
HTTPStatusErrorMetadata = "aserto-http-statuscode"
1616
)
1717

18-
func CustomErrorHandler(ctx context.Context, gtw *runtime.ServeMux, runtimeMarshaler runtime.Marshaler, httpResponseWriter http.ResponseWriter, httpRequest *http.Request, err error) {
18+
func CustomErrorHandler(
19+
ctx context.Context,
20+
gtw *runtime.ServeMux,
21+
runtimeMarshaler runtime.Marshaler,
22+
httpResponseWriter http.ResponseWriter,
23+
httpRequest *http.Request,
24+
err error,
25+
) {
1926
if err == nil {
2027
runtime.DefaultHTTPErrorHandler(ctx, gtw, runtimeMarshaler, httpResponseWriter, httpRequest, err)
2128
}

errors.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
var (
2525
ErrUnknown = NewAsertoError("E00000", codes.Internal, http.StatusInternalServerError, "an unknown error has occurred")
2626

27-
asertoErrors = make(map[string]*AsertoError)
27+
asertoErrors = make(map[string]*AsertoError) //nolint:gochecknoglobals
2828
)
2929

3030
func NewAsertoError(code string, statusCode codes.Code, httpCode int, msg string) *AsertoError {
@@ -51,8 +51,8 @@ func (e *AsertoError) Data() map[string]string {
5151
// SameAs returns true if the provided error is an AsertoError
5252
// and has the same error code.
5353
func (e *AsertoError) SameAs(err error) bool {
54-
aErr, ok := err.(*AsertoError)
55-
if err == nil || !ok {
54+
var aErr *AsertoError
55+
if ok := errors.As(err, &aErr); err == nil || !ok {
5656
return false
5757
}
5858

@@ -121,7 +121,8 @@ func (e *AsertoError) Err(err error) *AsertoError {
121121

122122
c.errs = append(c.errs, err)
123123

124-
if aErr, ok := err.(*AsertoError); ok {
124+
var aErr *AsertoError
125+
if ok := errors.As(err, &aErr); ok {
125126
for k, v := range aErr.data {
126127
if _, ok := c.data[k]; !ok {
127128
c.data[k] = v
@@ -167,7 +168,7 @@ func (e *AsertoError) Str(key, value string) *AsertoError {
167168

168169
func (e *AsertoError) Int(key string, value int) *AsertoError {
169170
c := e.Copy()
170-
c.data[key] = fmt.Sprintf("%d", value)
171+
c.data[key] = strconv.Itoa(value)
171172
return c
172173
}
173174

@@ -185,7 +186,7 @@ func (e *AsertoError) Int64(key string, value int64) *AsertoError {
185186

186187
func (e *AsertoError) Bool(key string, value bool) *AsertoError {
187188
c := e.Copy()
188-
c.data[key] = fmt.Sprintf("%t", value)
189+
c.data[key] = strconv.FormatBool(value)
189190

190191
return c
191192
}
@@ -339,8 +340,8 @@ func UnwrapAsertoError(err error) *AsertoError {
339340

340341
// try to process Aserto error.
341342
for {
342-
aErr, ok := err.(*AsertoError)
343-
if ok {
343+
var aErr *AsertoError
344+
if ok := errors.As(err, &aErr); ok {
344345
return aErr
345346
}
346347

errors_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func TestWithGrpcError(t *testing.T) {
194194

195195
func TestWithHttpError(t *testing.T) {
196196
assert := require.New(t)
197-
aerr := cerr.NewAsertoError("E000001", codes.Unavailable, http.StatusServiceUnavailable, "failed to setup").WithHTTPStatus(http.StatusNotAcceptable)
197+
aerr := cerr.NewAsertoError("E000001", codes.Unavailable, http.StatusServiceUnavailable, "failed to setup").
198+
WithHTTPStatus(http.StatusNotAcceptable)
198199

199200
unAerr := cerr.UnwrapAsertoError(aerr)
200201
assert.Equal(http.StatusNotAcceptable, unAerr.HTTPCode)

go.mod

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
module github.com/aserto-dev/errors
22

3-
go 1.21
3+
go 1.22.10
4+
5+
toolchain go1.23.4
46

57
require (
6-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0
8+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0
79
github.com/pkg/errors v0.9.1
810
github.com/rs/zerolog v1.33.0
9-
github.com/stretchr/testify v1.9.0
10-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988
11-
google.golang.org/grpc v1.65.0
11+
github.com/stretchr/testify v1.10.0
12+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484
13+
google.golang.org/grpc v1.68.1
1214
)
1315

1416
require (
@@ -18,10 +20,10 @@ require (
1820
github.com/mattn/go-isatty v0.0.20 // indirect
1921
github.com/pmezard/go-difflib v1.0.0 // indirect
2022
github.com/rogpeppe/go-internal v1.12.0 // indirect
21-
golang.org/x/net v0.28.0 // indirect
22-
golang.org/x/sys v0.24.0 // indirect
23-
golang.org/x/text v0.17.0 // indirect
24-
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 // indirect
25-
google.golang.org/protobuf v1.34.2 // indirect
23+
golang.org/x/net v0.33.0 // indirect
24+
golang.org/x/sys v0.28.0 // indirect
25+
golang.org/x/text v0.21.0 // indirect
26+
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
27+
google.golang.org/protobuf v1.36.0 // indirect
2628
gopkg.in/yaml.v3 v3.0.1 // indirect
2729
)

0 commit comments

Comments
 (0)