-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FileAccess] Return error codes from store_*
methods.
#78289
Conversation
|
Maybe returning a bool for the write operations instead? To indicate success, and use the error method to check, makes the immediate check simpler, so you don't need to do Alternatively add a simple convenience function |
Changed return values to |
f6de7d8
to
82ba4ca
Compare
1e608ae
to
e513626
Compare
platform/android/java/lib/src/org/godotengine/godot/io/file/DataAccess.kt
Outdated
Show resolved
Hide resolved
val writtenBytes = fileChannel.write(buffer) | ||
if (writtenBytes > 0) { | ||
endOfFile = false | ||
} | ||
return (totalBytes == writtenBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like as long as any bytes are written, we should return true
especially as an error would trigger an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not writing all bytes is definitely a failure, but if it will trigger an exception (which seems to be the case for the file), there's no need for this check.
e513626
to
4c1df25
Compare
4c1df25
to
455c705
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updates to the Android section look good!
455c705
to
77c850b
Compare
77c850b
to
1baf07d
Compare
Note that this will break compatibility in C# and there's no way to provide compat methods because the only thing that changes is the return type. We could consider adding new methods instead (e.g.: |
Are we sure that So it looks like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be moved to the 4.2 file now that it exists
4b4545a
to
18193f9
Compare
Needs rebase. |
18193f9
to
a4b17e7
Compare
Thanks! Merged a bit too early - the CI failures are not caused by this PR but a previous merge batch. |
Could someone clarify that? Not arguing against the PR but I'm writing a higher-level abstraction and would appreciate some insight in the intended error handling |
I'm not sure why you would need any additional information, file write errors are non recoverable, the only thing you can do is close the file handle and assume that file, and disk it was on are gone. |
Also the amount of info we can get is limited and platform dependent, so it won't be consistent. But if you have some specific cases for it in mind, we can handle it by setting the last error value returned by |
There are tons of reasons why writing can fail, file/medium gone is just one of them. There may be permission issues, another process locking the handle, disk full, ... Even C provides minimal information with I'm not asking for a cross-platform API or error codes or so, just wondered if there's a particular design reason why the already existing |
Documentation doesn't explain the meaning of the bool return value. Is true returned on success or on error? The comments in this PR don't clarify it either. |
Changes
FileAccess
methods fromvoid store_*(...)
toError store_*()
.See #77398, I was not able to reproduce an issue (might be related to overzealous antivirus activity), but file writes can fail for various reasons, and returning error seems like a good idea.