Skip to content

Mention that ERR_FILE_EOF is not always an error #8590

@andreymal

Description

@andreymal

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions