-
-
Notifications
You must be signed in to change notification settings - Fork 619
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
G307: Why is defer os.File.Close bad? #453
Comments
Please see for more details this article https://www.joeshaw.org/dont-defer-close-on-writable-files/ and also the 3rd point on this https://blog.learngoprogramming.com/5-gotchas-of-defer-in-go-golang-part-iii-36a1ab3d6ef1. |
Thanks for reporting this. I am going to close it for now. |
The first update in the first blog post mentions that a common solution to this problem is to
The blog post seems mostly okay with this, except that
|
It seems like this was recently added, but without any justification. If a file close fails, there's no real recourse to that... what is one supposed to do with it?
I would actually imagine that defer foo() where foo returns an error is the bad case, except os.File.Close, which is clearly OK...
The text was updated successfully, but these errors were encountered: