Skip to content

Commit 587f084

Browse files
committed
Merge pull request #82595 from paulloz/fix-fileaccess-error-handling
Error handling for `FileAccess.get_file_as_*`
2 parents 357a57b + bf3f6e3 commit 587f084

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

core/io/file_access.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ class FileAccess : public RefCounted {
223223
static Vector<uint8_t> get_file_as_bytes(const String &p_path, Error *r_error = nullptr);
224224
static String get_file_as_string(const String &p_path, Error *r_error = nullptr);
225225

226-
static PackedByteArray _get_file_as_bytes(const String &p_path) { return get_file_as_bytes(p_path); }
227-
static String _get_file_as_string(const String &p_path) { return get_file_as_string(p_path); };
226+
static PackedByteArray _get_file_as_bytes(const String &p_path) { return get_file_as_bytes(p_path, &last_file_open_error); }
227+
static String _get_file_as_string(const String &p_path) { return get_file_as_string(p_path, &last_file_open_error); }
228228

229229
template <class T>
230230
static void make_default(AccessType p_access) {

doc/classes/FileAccess.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@
155155
<param index="0" name="path" type="String" />
156156
<description>
157157
Returns the whole [param path] file contents as a [PackedByteArray] without any decoding.
158+
Returns an empty [PackedByteArray] if an error occurred while opening the file. You can use [method get_open_error] to check the error that occurred.
158159
</description>
159160
</method>
160161
<method name="get_file_as_string" qualifiers="static">
161162
<return type="String" />
162163
<param index="0" name="path" type="String" />
163164
<description>
164165
Returns the whole [param path] file contents as a [String]. Text is interpreted as being UTF-8 encoded.
166+
Returns an empty [String] if an error occurred while opening the file. You can use [method get_open_error] to check the error that occurred.
165167
</description>
166168
</method>
167169
<method name="get_float" qualifiers="const">

0 commit comments

Comments
 (0)