Skip to content

Commit

Permalink
Add errcheck & misspell to golangci and fix their issues
Browse files Browse the repository at this point in the history
Signed-off-by: sazary <[email protected]>
  • Loading branch information
sazary committed May 21, 2022
1 parent 9e10beb commit 3dfd8d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ linters:
- gofumpt
- goimports
- revive
- misspell
- errcheck
disable-all: true

issues:
max-same-issues: 0
exclude-rules:
- path: _test.go
linters:
- errcheck

linters-settings:
errcheck:
exclude: scripts/errcheck_excludes.txt
goimports:
local-prefixes: github.com/prometheus/client_golang
gofumpt:
Expand Down
6 changes: 5 additions & 1 deletion prometheus/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ func (p *Pusher) push(ctx context.Context, method string) error {
}
}
}
enc.Encode(mf)
if err := enc.Encode(mf); err != nil {
return fmt.Errorf(
"failed to encode metric familty %s, error is %w",
mf.GetName(), err)
}
}
req, err := http.NewRequestWithContext(ctx, method, p.fullURL(), buf)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion prometheus/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ func ToFloat64(c prometheus.Collector) float64 {
}

pb := &dto.Metric{}
m.Write(pb)
if err := m.Write(pb); err != nil {
panic(fmt.Errorf("error happened while collecting metrics: %w", err))
}
if pb.Gauge != nil {
return pb.Gauge.GetValue()
}
Expand Down
5 changes: 5 additions & 0 deletions scripts/errcheck_excludes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// The following 2 methods always return nil as the error
(*github.com/cespare/xxhash/v2.Digest).Write
(*github.com/cespare/xxhash/v2.Digest).WriteString

(*bufio.Writer).WriteRune

0 comments on commit 3dfd8d0

Please sign in to comment.