-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Mention that ERR_FILE_EOF is not always an error #8590
Comments
This isn't true, it is an error to try read more than is available in the file, you should use some other method to read from the file, this error tells you that you are, in fact, reading too much, that's what the error is for, reading like this is not proper IMO and shouldn't be encouraged |
@AThousandShips why? It is never interpreted as an error in the
Is there a good reason why Godot shouldn't follow the same logic? |
Well those are not the same functions As I said I have an issue with suggesting behavior that I don't think is good code, and the method documentation says:
Reading like this makes it riskier and makes error handling harder, instead people should, in my opinion, read in a way that considers the data remaining Also it's just us here, please don't ping me 🙂 |
This implies calling And |
Yes, but that's different, it isn't provided an explicit length, you can do this way with providing a longer length, but I'd say that saying "don't worry" sends the wrong message, but again, taht's my opinion on this. We return an error, that error should be respected And especially, IMO, if you are reading in this way you are expected to know what you do |
Hm, there is actually a warning in if (read < p_length) {
WARN_PRINT("Reading less data than requested");
} But other implementations of Seems like a clear choice needs to be made:
|
Let's look at a naive implementation of error handling:
If the file is small enough,
get_buffer
reaches EOF, andget_error
returns 18 (ERR_FILE_EOF
).But unless the user expects exactly 65536 bytes in the buffer, it's not an error, and
ERR_FILE_EOF
can be ignored.This may be obvious for experienced users, but it's easy to overlook it.
I suggest mentioning somewhere (probably in the
FileAccess
documentation) that reaching EOF when reading dynamically sized data (i.e. when usingget_buffer
,get_line
and probably other methods) doesn't always indicate something bad and can be safely ignored in some cases.The text was updated successfully, but these errors were encountered: