Skip to content
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

Minor false positive when response body is passed to deferred function as parameter #60

Open
pellared opened this issue Jul 31, 2024 · 1 comment

Comments

@pellared
Copy link

pellared commented Jul 31, 2024

I got a minor false positive for a deferred response close like below:

	defer func(Body io.ReadCloser) {
		err := Body.Close()
		if err != nil {
			log.Printf("failed to close http response body, %v\n", err)
		}
	}(res.Body)

The workaround was to refactor to:

	defer func() {
		err := res.Body.Close()
		if err != nil {
			log.Printf("failed to close http response body, %v\n", err)
		}
	}()

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

@pellared
Copy link
Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant