Skip to content

fix: Add validation for corrupted database cache and downloads#114

Draft
ConsciousEnergy wants to merge 1 commit intoEpisk-pos:mainfrom
ConsciousEnergy:fix/database-corruption-validation
Draft

fix: Add validation for corrupted database cache and downloads#114
ConsciousEnergy wants to merge 1 commit intoEpisk-pos:mainfrom
ConsciousEnergy:fix/database-corruption-validation

Conversation

@ConsciousEnergy
Copy link

This PR adds robust validation to prevent and recover from corrupted database cache scenarios.

Problem:
When the database file is missing or corrupted, the app would cache HTML error pages (404 responses)
in IndexedDB, leading to "file is not a database" errors on subsequent loads.

Solution:

  • Validates cached data before use (size >100MB + SQLite magic bytes check)
  • Validates downloaded data before caching
  • Detects HTML error pages early via content-type checking
  • Automatically clears corrupted cache and triggers fresh download
  • Provides clear error messages with download instructions

Related Issues:

Testing:

  • ✅ Verified corrupted cache is detected and cleared
  • ✅ Verified fresh download works correctly
  • ✅ Verified validation prevents invalid data caching

Files Changed:

  • src/services/database.ts - Added validation logic
  • src/services/dbCache.ts - Cleaned up debug logs
  • src/services/queryService.ts - Minor cleanup

- Add cache validation (size >100MB + SQLite magic bytes check)
- Add download validation before caching
- Add content-type checking to detect HTML error pages early
- Auto-recovery: clear corrupted cache and trigger fresh download
- Better error messages with download instructions

Fixes Episk-pos#53 (partial - addresses root cause of corrupted cache)

Files:
- src/services/database.ts
- src/services/dbCache.ts
@bryanchriswhite
Copy link
Contributor

Thanks again @ConsciousEnergy for stepping up! ❤️‍🔥

As I was reviewing #53, I realized that I did make some changes in this direction already, but after discussing it with Claude, it seems like left some room for improvement, and the changes you propose include some additional improvements still.

Here's the convo I had with Claude:
image

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.

Error: no such table: ElementPropertiesPlus

2 participants