-
Notifications
You must be signed in to change notification settings - Fork 33
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
False positive with body close inside separate function #30
Comments
@timakin Any feedback on the above? This pattern is quite common in many projects. In fact, the following code that is demonstrated in this links closes the body inside another function: https://blog.golang.org/context The tool would raise a flag against I have creative ways to work around this but I think this tool ignores certain practices I see from the community. |
@renta Did you come up with a way around this? I have some creative ways, like in my example above, I would have the |
@justinpage I've not found a proper way to fix this issue, so I've used //nolint:bodyclose before isAppReady function to suppress this check. |
Another example: resp, err := http.DefaultClient.Do(req) //nolint:bodyclose // linters bug
if err != nil {
return rc, err
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
logger.GetLogger().Errorf("can not to close body: %s", err.Error())
}
}(resp.Body) |
I think the same happened here. I opened ory/kratos#1727 for the same reason, I think. Any news, @timakin? |
IntelliJ/Goland right now auto generates
and this linter doesn't accept that |
It works for me. This issue is for another reason. |
And chance in a config file you could allow us to provide a regexp for matching our closers? Using In my case I have a package called
It would be nice if I could specify that anything matching |
I have to wonder how the false positive / actual positive ratio is with this bug unresolved for over 2 years 🤔 For some reason I get new warnings after upgrading to golangci-lint 1.52.0 from 1.50.1, is it expected to find more issues now? |
Unfortunately bodyclose fails if the body is closed in a separate function: timakin/bodyclose#30
I think the generic solution is adding the ignore rules, like if a response or body is passed to a defined in the rules function, then ignore that case |
I think that bodyclose produces false positive warning on this code: response body is closed in a separate function inside each logic case. I can not use defer response.Body.Close() due to infinite loop with ticker.
The text was updated successfully, but these errors were encountered: