Error handling on restore state
See original GitHub issueWe are using this with LZ-compression, but are running into problems especially on Firefox with restoring state. Firefox often can’t decompress the state we have put in there with LZ (don’t know why), but this results in the state being “restored” to null.
How would you recommending handling this, so instead of restoring a key state to null, it would just act as if there was nothing to restore, and use the default state defined in the reducer?
This is our current setup for reference:
persistStore(store, {
whitelist: ['chat', 'contacts', 'user'],
transforms: [chatMessageHistoryTransform, compressor]
}, rehydrationCallback);
So for example the LZ decompress of “contacts” might fail, and then we get out null instead of the default (an empty array []).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Restoring Your App's State | Apple Developer Documentation
This sample project demonstrates how to preserve your appʼs state information and restore the app to that previous state on subsequent launches.
Read more >Restore Using TRY…CATCH might fail with error « Help
Restoring this backup in SQL 2012 using TRY CATCH would fail. Tip: Whenever I see any “Error: 928, Severity: 20, State: 1.
Read more >ERR03-J. Restore prior object state on method failure
Although the logic restores the object's original state in the absence of this exception, the rollback code fails to execute in the event...
Read more >How to process multiple error codes from a database restore ...
CATCH block but as a restore error tends to generate two codes, the first being the actual error, and the second being a...
Read more >Best practices for error catching and handling
Restore state. After recovering from an error, your program needs to have the correct state. If it doesn't, then you haven't really recovered ......
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 Free
Top 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

Another update: I tried validating the rehydrated state in my reducer on the REHYDRATE event, but because of autoHydrate.js#L37 my (fixed) reducer state is always overwritten by the incoming garbage from the corrupted stored state.
I finally ended up writing middleware, that will modify the REHYDRATE payload if it is invalid. Don’t know if this is the “correct” way to do it, but here is the code:
Yes, it has been working well for us so far.