Passing null or undefined as a value to setItem or multiSet doesn't result in an error.
See original GitHub issueCurrent behavior
If null
or undefined
is passed as a value to setItem
or multiSet
then no error is generated and therefore any listening .catch()
methods/catch
blocks/error callbacks don’t fire to let you know something went wrong.
Expected behavior
I would expect an error to be generated in the same way as if any other invalid value was passed e.g. number, bool, object.
Repro steps
try {
await AsyncStorage.setItem('aTestKey', null, e => {
console.error(`Error in callback`, { e });
});
} catch (e) {
console.error(`Error in catch`, { e });
}
Environment
- Async Storage version: 1.6.2
- React-Native version: 0.61.4
- Platform tested: Android
- Logs/Error that are relevant: N/A
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Unable to work with React Native Async Storage
In case someone is using AsyncStorage.multiSet([]) , make sure that none of your values is null or undefined . Otherwise, it won't work...
Read more >API | Async Storage - GitHub Pages
Promise resolving with a string value, if entry exists for given key , or null otherwise. Promise can also be rejected in case...
Read more >Storage.setItem() - Web APIs - MDN Web Docs
A string containing the value you want to give the key you are creating/updating. Return value. None ( undefined ). Exceptions. setItem() ...
Read more >A guide to React Native's AsyncStorage - LogRocket Blog
AsyncStorage is an unencrypted and asynchronous data storage system in React Native that allows users to persist data offline.
Read more >cross-local-storage - npm Package Health Analysis - Snyk
Learn more about cross-local-storage: package health score, popularity, ... If you pass null or undefined, the value will be removed.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fantastic, thanks @Krizzu - much appreciated 👍
@leemcmullen Yes, you’re right - the error is being swallowed for
null
/undefined
in here.Going to fix that 😃