Skip to content

fix(storage): prevent history wipe on transient dataStore errors#1052

Open
ifoche wants to merge 1 commit intodevelopmentfrom
fix/history-wipe-on-storage-error
Open

fix(storage): prevent history wipe on transient dataStore errors#1052
ifoche wants to merge 1 commit intodevelopmentfrom
fix/history-wipe-on-storage-error

Conversation

@ifoche
Copy link
Copy Markdown
Member

@ifoche ifoche commented Mar 4, 2026

Summary

  • Fix StorageDataStoreClient.getObject() silently returning undefined on all errors (network, 5xx, timeout), which was indistinguishable from "key not found" (404)
  • This caused sync history to be wiped whenever a transient error occurred during a saveObjectInCollection call — the existing history was treated as empty and overwritten with just the new entry
  • Now getObject returns undefined only for 404 and re-throws on transient errors. Same fix applied to getMetadataByKey()
  • StorageConstantClient was verified to not have this bug (it uses the models API which returns empty arrays, not 404s)
  • Adds 6 unit tests for the error handling behavior

Related Tasks

Test plan

  • Run yarn test — all 394 tests pass (48 files)
  • Run yarn build core-app — builds cleanly
  • Manual: trigger a sync while the DHIS2 server is under load; verify history is preserved even if some requests are slow
  • Manual: verify that a genuinely missing dataStore key still returns undefined (e.g., first-time app setup works correctly)
  • Manual: verify sync reports are saved correctly after a successful sync

🤖 Generated with Claude Code

StorageDataStoreClient.getObject() was catching ALL errors and returning
undefined, making network failures indistinguishable from missing keys.
Collection mutation methods (saveObjectInCollection, etc.) treated
undefined as "empty collection" via ?? [], then overwrote the dataStore
key — wiping sync history on any transient error.

Now getObject returns undefined only for 404 (key not found) and
re-throws on network errors, 5xx, and timeouts. Also applies the same
fix to getMetadataByKey. Adds 6 unit tests.

StorageConstantClient was verified to not have this bug — it queries
constants via the models API which returns empty arrays (not 404s) for
missing entries.

Closes: https://app.clickup.com/t/869c32tg2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bundlemon
Copy link
Copy Markdown

bundlemon Bot commented Mar 4, 2026

BundleMon

No change in files bundle size

Groups updated (1)
Status Path Size Limits
Build Folder
./**/*
2.78MB (-52B 0%) +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant