What are the possible failure cases of React Native's AsyncStorage?
asyncstorage, react-native
Solution
The code is open source, you can see when the calls fail, for example here on android or here for ios.
The `getItem` call, fails, for example when requiring a nonexistent item. Other example may be `Failed to create storage directory.` which you can see in the ios module (for example when there's not enough space on device).
Edit:
According to the documentation of `react-native-community/async-storage` ,`getItem` won't fail when requiring a nonexistent item, it will just return `null`.
Problem
React Native provides the `AsyncStorage` library as a way to store persistent data in RN apps. In general, AsyncStorage is pretty straightforward to use, except for one aspect: Both of the main `AsyncStorage` functions, `AsyncStorage.getItem` and `AsyncStorage.setItem` return `Promise`s. This is simple enough to understand: The actual querying or saving done by the function runs in the background, and the getting or saving of items might fail, requiring us to `catch` the error. However, it seems that nowhere in the React Native documentation is it specified what, exactly, are the failure cases of `AsyncStorage` or which errors one should expect when calling `setItem`or `getItem`. Of course, one can deduce what might be a few of the error cases: One might try to `getItem` using an inexistent key, or one might try to `setItem` in a full or nearly full store, and the OS might refuse to release more disk space for your app, but it is frustrating not to have a full list. It would be nice to know how exactly `AsyncStorage` might fail, so that people who are developing React Native apps which use data persistence might know exactly which failure cases they need to handle.