mobx-persist icon indicating copy to clipboard operation
mobx-persist copied to clipboard

Detecting crashes from restored state

Open aphillipo opened this issue 6 years ago • 5 comments

Hi There,

Not sure if this have come up yet but if my app crashes within a short amount of time of running hydrate I'd like to clear all the persistence. Seems like a useful feature for obvious reasons, what do you thing?

Close if you can't help! I'm really impressed with how well this library is working with react-navigation!

aphillipo avatar Oct 22 '17 10:10 aphillipo

React Native Android? Can you provide your crash logs?

pinqy520 avatar Oct 22 '17 11:10 pinqy520

Sorry to have not made myself clear: I want a feature that every time the App crashes within 200ms of a hydrate I can clear that hydrate information. The reason I want this is if the App gets into a persistent crashing state there will be no way to recover. Does this make more sense as a feature request rather than an issue with your library?

aphillipo avatar Oct 22 '17 13:10 aphillipo

OK, I understand now. You mean that some wrong persisted data will cause some JS errors, then this wrong data should be deleted. You can try this:

hydrate('some', someStore).catch(e => { 
    console.warn(e)
    // TODO: delete the state
})

pinqy520 avatar Oct 22 '17 14:10 pinqy520

Yes perfect start, just wondering if the catch will always fire or if there will be a small delay or another part of the application when receiving this information will crash?

aphillipo avatar Oct 22 '17 14:10 aphillipo

I can confirm the repopulation of the state crashes the App if it's bad or undefined even with the suggested catch in place upon hydrate. I'm going to need to:

a) trap all the errors in my app b) figure out if a hydrate was called recently (200ms?) c) maybe send ourselves the bad hydrate data d) delete the hydrate data and (somehow) restart the app.

Will let you know when I get to it and write some example tests/components for the different crash states.

aphillipo avatar Nov 06 '17 15:11 aphillipo