react-native-photos-framework
react-native-photos-framework copied to clipboard
Improve errors in saveAssetsToDisk / saveAssetToDisk
Nice to see this project moving along!
While upgrading our native dependencies I noticed there is now support for resizing and saving assets to disk, this allows us to get rid of some own native code for that, nice! 🙏
However, I noticed that file writing errors would be silently ignored. This can happen e.g. if we specify a directory which isn't writable or doesn't exist (bugs), but also if the disk is full, which we have seen in our logs several times previously.
- Change signature of
RNPFImageResizer.createResizedImagecompleteBlockto(NSString *path, NSError *error), so it can report actual NSError objects. I changed the order of arguments to be more conventional "objective-c" (which I don't know much about, but according to http://nshipster.com/nserror/). - Have not converted the contents of previous
NSString *errorargument, because they were not being added to the result before (I gave up while reading up on creating errors with domain/code etc.). Thesuccesswill still befalsein those cases, since thepathis set tonil. It's a good idea to do this, but I'm happy with just file errors getting reported. - Convert the NSError into JSON in the result
error, (rather thanlocalizedDescriptionas before), to be able to log/display it as needed. This is the same representation that gets returned withreject(nil, nil, nsError). I recommend to do the same inupdateAssetstoo but haven't changed it. - Change
saveAssetToDiskso the promise is either rejected with the error from native (before it was needed or resolved with thefileUrl(localIdentifiershouldn't be of interest since you are working on a single asset). Updated example to reflect this change.