fix: hydrate AsyncStorage keys independently - #11
Open
robbe1912 wants to merge 2 commits into
Open
Conversation
All four persisted keys (settings, chat preferences, active project, last session map) were wrapped in a single try/catch. One corrupt value aborted all remaining hydration steps, leaving the user with defaults even for keys that were intact. Wrap each key in its own try/catch and drop the corrupt value so the next write replaces it cleanly. Run them in parallel via Promise.all since the order doesn't matter.
Oracle review flagged a contract drift: the per-key try/catch added in this branch also purges the corrupt key via AsyncStorage.removeItem, but docs/state-and-data.md only said 'hydration failures are ignored and defaults are kept'. Document the new behavior explicitly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
If any single AsyncStorage key holds a corrupt value (e.g. truncated JSON written by a crashed prior run), the entire outer \ ry/catch\ in \hydrateState\ fires and the remaining keys are silently skipped. The user is left with defaults for everything, not just the corrupt key.
Fix
Rewrite hydration as a \loadKey(key, parse, apply)\ helper with per-key \ ry/catch. A corrupt value is logged and purged (\AsyncStorage.removeItem) so subsequent writes replace it cleanly; the remaining keys hydrate normally.
Files changed
Validation
pm run typecheck\ ✓
pm run lint\ ✓
pm run test:fake-server:self\ ✓