Skip to content

Commit 1555ed8

Browse files
committedNov 2, 2020
Fix unchecked call to io.Copy
After prometheus-community#49 was merged to master the build failed due to a linting error: GO111MODULE=on /go/bin/golangci-lint run ./... exporter/util.go:162:10: Error return value of `io.Copy` is not checked (errcheck) io.Copy(ioutil.Discard, resp.Body) ^ make: *** [Makefile.common:192: common-lint] Error 1 build failure here: https://app.circleci.com/pipelines/github/prometheus-community/json_exporter/28/workflows/e2c53db3-d3a3-4faa-a5a6-3b1fbb5754a0/jobs/71 Signed-off-by: Konstantinos Koukopoulos <koukopoulos@aisera.com>
1 parent f76b12d commit 1555ed8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎exporter/util.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ func FetchJson(ctx context.Context, logger log.Logger, endpoint string, config c
159159
}
160160

161161
defer func() {
162-
io.Copy(ioutil.Discard, resp.Body)
162+
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
163+
level.Error(logger).Log("msg", "Failed to discard body", "err", err) //nolint:errcheck
164+
}
163165
resp.Body.Close()
164166
}()
165167

0 commit comments

Comments
 (0)