-
Notifications
You must be signed in to change notification settings - Fork 36
Minor false positive when response body is passed to deferred function as parameter #60
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
Comments
Might be related to #51 |
pellared
added a commit
to open-telemetry/opentelemetry-go-contrib
that referenced
this issue
Aug 1, 2024
Add https://golangci-lint.run/usage/linters/#bodyclose linter. Fix a few issues in tests detected by the linter. False positives reported: - timakin/bodyclose#59 - timakin/bodyclose#60
luca-filipponi
pushed a commit
to luca-filipponi/opentelemetry-go-contrib
that referenced
this issue
Aug 9, 2024
Add https://golangci-lint.run/usage/linters/#bodyclose linter. Fix a few issues in tests detected by the linter. False positives reported: - timakin/bodyclose#59 - timakin/bodyclose#60
@timakin This is quite a big downside for other project adopt it. As per #50 I add a helper function: // sneakyBodyClose closes the body and ignores the error.
// This is useful to close the HTTP response body when we don't care about the error.
func sneakyBodyClose(body io.ReadCloser) {
if body != nil {
_ = body.Close()
}
} And now bodyclose cannot find |
Same problem is you do want to do both, close the body and log the error:
Alternative is to keep duplicating hundreds of lines or keep ignoring the error. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I got a minor false positive for a deferred response close like below:
The workaround was to refactor to:
Tested with https://github.com/golangci/golangci-lint/releases/tag/v1.59.1 and https://github.com/open-telemetry/opentelemetry-go-contrib.
PR for reference: open-telemetry/opentelemetry-go-contrib#5962
The text was updated successfully, but these errors were encountered: