-
-
Notifications
You must be signed in to change notification settings - Fork 664
(atomWithStorage): Exceptions from Storage providers should not be silenced #1347
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
Comments
Good point. We should only catch if (a) storage doesn't have an item or (b) if JSON.parse fails with defaultStorage. I can work on it unless anyone else would like to take it. |
Would the solution to this be something like this, or is there a better way? const handleErr = ()=>{
//Logic for deciding if return initialValue or not
}
const getInitialValue = () => {
try {
const value = storage.getItem(key)
if (value instanceof Promise) {
return value.catch(handleErr)
}
return value
} catch (e) {
return handleErr(e)
}
} |
It's close. We should return initial value if (a) or (b), otherwise throw the error. |
I'll work on it. |
Could you try #1363? |
Yeah, that works! |
At the moment if anything throws inside StorageSync the error will be swallowed and not even logged in console.
This behavior is very unfriendly.
https://codesandbox.io/s/jotai-useatomcallback-async-error-forked-zr737n?file=/src/App.tsx:187-470
I had a bug where zod couldn't parse data but took me a while to figure out because of suppressed exceptions.
IMHO exceptions should be at the very least logged with
console.error
if not made fatal.The text was updated successfully, but these errors were encountered: