-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os: document that NewFile can return nil for invalid fd #20023
Comments
I don't think this is a documentation bug; NewFile can only return nil if someone passes a negative value. Given we cannot change the signature now, I argue this method should panic, as the construction of an invalid value of fd is a programming error. |
panic or |
Noting in the doc that
Moving this to |
CL https://golang.org/cl/41211 mentions this issue. |
It has always behaved this way (return nil for fd < 0, back to 2008), but it does seem weird that fd=-1 is handled differently from fd=1e9. Perhaps we should return a non-nil *File that returns an appropriate error from future operations (whatever happens when you use the fd later). |
Actually, all the methods already return ErrInvalid for nil *File and the docs for ErrInvalid already say "methods on File will return this error when the receiver is nil". So maybe this is fine and just a doc update is needed. |
Based on discussion with @golang/proposal-review (reflected above), the doc change seems to be the best, least disruptive path forward. Since nil is usable and has been forever, it seems OK to continue that and just document how it happens. |
Since the
os.NewFile
function does not return an error value, one might assume that the function always returns a non-nil value. A line in the docs saying otherwise might save some users a little grief.The text was updated successfully, but these errors were encountered: