Error normalization (ongoing, tracking issue) #460
Description
I just wrote a function that renames a temporary file created by a stream to its final name (in my case the SHA-256 hash of the contents of the file is going to be the final name, so I don't know what it is until it's all there).
I use RNFetchBlob.fs.mv
(link to fs.js).
That lead me to a hunt for the actual Java and iOS (Swift) methods used to rename the file (File.renameTo
for Java, moveItemAtURL
for iOS).
There is zero documentation of errors, and when I get down to it, I don't really know what the errors are that I'm going to get.
Some methods have a fixed string set in this project's source code - but a different one for Java and iOS versions? For example, promise.reject("ReadFile Error", err.getLocalizedMessage());
is used in readFile
(Android) - but on iOS that string seems to be reject(@"RNFetchBlob failed to read file", err, nil);
- and readStream
has completely different error messages yet again...
By the way (see readStream
, this function seems to have a single error message about "encoding" for everything incl. FileNotFound
exceptions?
("Failed to convert data to "+encoding+" encoded string, this might due to the source data is not able to convert using this encoding."
)
In my case I could not simply invoke the mv
and handle an error - because I simply don't know what "destination file exists" errors are going to look like.
It would be nice to have documentation about (common) errors (like "file not found" for read file operations or "file exists" for write operations - and do they silently overwrite or not?) as well as a way to catch those common errors (fixed Error.name or Error.message (beginning of the string) independent of the platform.
Yeah, that could be a major effort :-( Just a suggestion.
It's of course possible to program without any such assurances, but then, in the specific example to have one, I have to do more I/O and use other functions to check for existence before the actual operation - which causes another issue because now I need to make the function "atomic", since a check for existence followed by access might be interrupted my another I/O event that creates the file in the meantime, even in single-threaded Javascript that's not safe. That's why it would be nice to be able to just do an operation and handle any errors later (like node.js philosophy for file operations).