Skip to content

Commit 3dfd8d0

Browse files
committed
Add errcheck & misspell to golangci and fix their issues
Signed-off-by: sazary <[email protected]>
1 parent 9e10beb commit 3dfd8d0

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ linters:
1212
- gofumpt
1313
- goimports
1414
- revive
15+
- misspell
16+
- errcheck
1517
disable-all: true
1618

1719
issues:
1820
max-same-issues: 0
21+
exclude-rules:
22+
- path: _test.go
23+
linters:
24+
- errcheck
1925

2026
linters-settings:
27+
errcheck:
28+
exclude: scripts/errcheck_excludes.txt
2129
goimports:
2230
local-prefixes: github.com/prometheus/client_golang
2331
gofumpt:

prometheus/push/push.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@ func (p *Pusher) push(ctx context.Context, method string) error {
273273
}
274274
}
275275
}
276-
enc.Encode(mf)
276+
if err := enc.Encode(mf); err != nil {
277+
return fmt.Errorf(
278+
"failed to encode metric familty %s, error is %w",
279+
mf.GetName(), err)
280+
}
277281
}
278282
req, err := http.NewRequestWithContext(ctx, method, p.fullURL(), buf)
279283
if err != nil {

prometheus/testutil/testutil.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ func ToFloat64(c prometheus.Collector) float64 {
101101
}
102102

103103
pb := &dto.Metric{}
104-
m.Write(pb)
104+
if err := m.Write(pb); err != nil {
105+
panic(fmt.Errorf("error happened while collecting metrics: %w", err))
106+
}
105107
if pb.Gauge != nil {
106108
return pb.Gauge.GetValue()
107109
}

scripts/errcheck_excludes.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// The following 2 methods always return nil as the error
2+
(*github.com/cespare/xxhash/v2.Digest).Write
3+
(*github.com/cespare/xxhash/v2.Digest).WriteString
4+
5+
(*bufio.Writer).WriteRune

0 commit comments

Comments
 (0)