godotengine / godotengine/godot-docs
Mention that ERR_FILE_EOF is not always an error
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
Let's look at a naive implementation of error handling:
```gdscript
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.