-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
Labels
Description
Let's look at a naive implementation of error handling:
var fp := FileAccess.open("res://myfile.txt", FileAccess.READ)
var data := fp.get_buffer(65536)
if fp.get_error():
print("PANIK I/O IS BROKEN YOUR HDD IS DYING AAAAAAA")If the file is small enough, get_buffer reaches EOF, and get_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 using get_buffer, get_line and probably other methods) doesn't always indicate something bad and can be safely ignored in some cases.
AThousandShips