Merge pull request #82595 from paulloz/fix-fileaccess-error-handling

Error handling for `FileAccess.get_file_as_*`
This commit is contained in:
Rémi Verschelde 2023-10-11 22:37:54 +02:00
commit 587f084200
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 4 additions and 2 deletions

View file

@ -223,8 +223,8 @@ public:
static Vector<uint8_t> get_file_as_bytes(const String &p_path, Error *r_error = nullptr); static Vector<uint8_t> get_file_as_bytes(const String &p_path, Error *r_error = nullptr);
static String get_file_as_string(const String &p_path, Error *r_error = nullptr); static String get_file_as_string(const String &p_path, Error *r_error = nullptr);
static PackedByteArray _get_file_as_bytes(const String &p_path) { return get_file_as_bytes(p_path); } static PackedByteArray _get_file_as_bytes(const String &p_path) { return get_file_as_bytes(p_path, &last_file_open_error); }
static String _get_file_as_string(const String &p_path) { return get_file_as_string(p_path); }; static String _get_file_as_string(const String &p_path) { return get_file_as_string(p_path, &last_file_open_error); }
template <class T> template <class T>
static void make_default(AccessType p_access) { static void make_default(AccessType p_access) {

View file

@ -155,6 +155,7 @@
<param index="0" name="path" type="String" /> <param index="0" name="path" type="String" />
<description> <description>
Returns the whole [param path] file contents as a [PackedByteArray] without any decoding. Returns the whole [param path] file contents as a [PackedByteArray] without any decoding.
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.
</description> </description>
</method> </method>
<method name="get_file_as_string" qualifiers="static"> <method name="get_file_as_string" qualifiers="static">
@ -162,6 +163,7 @@
<param index="0" name="path" type="String" /> <param index="0" name="path" type="String" />
<description> <description>
Returns the whole [param path] file contents as a [String]. Text is interpreted as being UTF-8 encoded. Returns the whole [param path] file contents as a [String]. Text is interpreted as being UTF-8 encoded.
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.
</description> </description>
</method> </method>
<method name="get_float" qualifiers="const"> <method name="get_float" qualifiers="const">