New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable ErrCheck #5386
Enable ErrCheck #5386
Conversation
…rg/errcheck # Conflicts: # cmd/cluster-agent/api/v1/install.go # pkg/autodiscovery/integration/config.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this linter makes sense to me, and the approach of ignoring the existing non-check errors in this initial PR sounds good as well.
How much does this linter add to the linter wall clock time on a dev env ? Does it support linting only a subset of the packages? (wouldn't want to slow down invoke test
by too much, especially when invoke test --targets=./pkg/foo
is specified for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember if we have subsequent action planned to handle all the places requiring the //nolint:errcheck
assertion, but I guess we will see later.
.golangci.yml
Outdated
linters-settings: | ||
errcheck: | ||
# Disable warnings for `fmt` and `log` packages. | ||
ignore: fmt:.*,github.com/DataDog/datadog-agent/pkg/util/log:.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the huge number of http.ResponseWriter.write(...)
requiring the //nolint:errcheck
would it be possible to exclude it ? (possible errors seem relatively safe to ignore https://golang.org/pkg/net/http/#pkg-variables but I may be wrong about that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to ignore http.ResponseWriter.Write
a couple of days ago but because of golangci/golangci-lint#656, it seems I can only ignore all the Write
methods from http package (and not the specific method http.ResponseWriter.Write).
Upgrading golangci-lint requires extra work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @prognant, I'm not a fan of all the //nolint:errcheck
. We might want to ignore all Write()
call from the http package at this point.
As a more general review, we ignore so many warning in this PR that I wonder if it's worth it. I feel like it's increasing the code complexity and we're not gaining a lot. Like all call to json
or yaml
should actually be fixed instead of being ignore. WDYT ?
I'm afraid people are not actually going to check their error but just pollute the code base with //nolint:errcheck
. At this point we will fall back to where we are now: relying on review instead of the linter. That's why I didn't enabled it in the first PR for golangci: way to many warning we might not want to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my 2 cents:
- I guess it makes sense for the linter to ignore all
Write
calls from the http package. Let's add a fixme comment linking to the golanci issue, we might be able to make the ignore rule more specific when we upgrade golangci - I prefer explicitly calling out all instances of unhandled errors with
//nolint:errcheck
than having errors "silently" ignored in the code (by "silent" here, I mean that the calling code doesn't even acknowledge that the call can return an error) - merging this with a bunch of
//nolint:errcheck
is simpler to review and merge, and already provides value for future code we'll add to the codebase. But yes please create tasks in the backlog about cleaning up all these//nolint:errcheck
(one card per team owning related packages)
Measurements based of the median of 3 runs for
after:
I only enabled a new linter and so the behavior is the same as before. |
.golangci.yml
Outdated
linters-settings: | ||
errcheck: | ||
# Disable warnings for `fmt` and `log` packages. | ||
ignore: fmt:.*,github.com/DataDog/datadog-agent/pkg/util/log:.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @prognant, I'm not a fan of all the //nolint:errcheck
. We might want to ignore all Write()
call from the http package at this point.
As a more general review, we ignore so many warning in this PR that I wonder if it's worth it. I feel like it's increasing the code complexity and we're not gaining a lot. Like all call to json
or yaml
should actually be fixed instead of being ignore. WDYT ?
I'm afraid people are not actually going to check their error but just pollute the code base with //nolint:errcheck
. At this point we will fall back to where we are now: relying on review instead of the linter. That's why I didn't enabled it in the first PR for golangci: way to many warning we might not want to fix.
At first, I wanted to fix everything but I realized that I do not well enough the impacted code to do the changes.
I think
There are some rare cases where ignoring error is the right thing. |
…rg/errcheck # Conflicts: # cmd/cluster-agent/app/app.go # pkg/clusteragent/clusterchecks/dispatcher_main.go # pkg/clusteragent/clusterchecks/handler.go # pkg/forwarder/forwarder_health.go # pkg/jmxfetch/jmxfetch.go
What does this PR do?
This PR enables ErrCheck.
errcheck
is a program for checking for unchecked errors in go programs.Additional Notes
As handling errors may lead to behavior changes, I disabled existing warnings with
//nolint:errcheck
.New codes should explicitly handle the errors. In the rare cases you want to discard the error use something like
_ := MyFunction()
.