-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Please revert #10002 FS library returning (size_t)-1 #10360
Comments
…if#10002)" This reverts commit 0ab2c58. Fixes: espressif#10360
As noted in #9992, (by me_no_dev) this change matches the Arduino File class in the Arduino SD library. I don't believe returning -1 necessitates changing all the other methods args to ints as that would be even more 'non-standard' compared to the Arduino SD library Looking at the C fn ftell(), it returns -1 on error so I suppose that was the template for the Arduino functions, but due to the word size, they opted to returned an unsigned to get the maximum available range on restricted word length CPU's In any case, an experienced C programmer would expect the 'position' function to return -1 on error. Please re-apply the original pull request to provide a usable error return and to be compatible with the Arduino File class. |
Well it isn't accepted and @me-no-dev also mentioned via chat that I should find other ways. Don't get me wrong, I do completely understand that reporting an error state which could also be a valid state is not good either, but what we're ending up with now is that we need to check at numerous places whether we're dealing with either However the situation is now that we can't make a proper fix as it will break Arduino compatibility. (meaning turning all these into signed values whenever an error could be expected) So which one is the worst? Meaning I still feel strongly for reverting this commit for now and then re-do this but now with proper testing. As how it is now, it is unusable as it simply does cause issues which are hard to track. TL;DR |
By the way just to make it clear how inconsistent it all is now... size_t VFSFileImpl::position() const {
if (_isDirectory || !_f) {
return 0;
}
return ftell(_f);
} |
I did not manage to track down the .h file for ftell() but I assume it is the standard C declaration in which case it will return -1 on error, |
Yup, this will take some time to do "properly". For now, it is introducing bugs to FS.
I agree, +1. @me-no-dev - what would be the reason to not revert this change? |
Perhaps in the mean time update the docs for VSFileImpl::position to say |
The only reason why this was merged and will not be reverted is that this is how it works in upstream Arduino (in the SD Card class). I also do not like it and do not find it proper, but for the sake of being compatible, it had to be done. |
Board
Any
Device Description
Hardware Configuration
Version
latest master (checkout manually)
IDE Name
PlatformIO
Operating System
Windows 11
Flash frequency
Any
PSRAM enabled
yes
Upload speed
115200
Description
The change introduced by this commit has all kinds of side-effects as
position()
is used in several other functions, some of which expect this to be a signed int.If you really need to return an error code for this function, then all (!!!) position related code should expect a signed type.
Returning
(size_t)-1
is always something that should be frowned upon.For now, please revert this commit.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: