Fix critical data loss bugs and improve error handling

## Critical Fixes
- Fix CRITICAL-1: Empty scans no longer delete entire library
  - Use timestamp-based tombstone logic instead of path-based
  - Only mark missing if livePaths is not empty

- Fix CRITICAL-2: Re-scanned files now return from deleted state
  - Add deleted=false to SongsCompanion.insert in both scanners

## High Priority Fixes
- HIGH-1: Fix SQLite variable limit crash on large libraries
  - Replace isNotIn() with timestamp comparison (O(1) not O(n))

- HIGH-2: Fix UI freezing during scan
  - Throttle progress updates (every 50 files or end of scan)

- HIGH-3: Add error handling for scan failures
  - Wrap scanFolders/scanAndroidMediaStore in try/catch
  - Display scanError banner in LibraryScreen

- HIGH-4: Add error handling for playback failures
  - Wrap loadPlaylist in try/catch

## Medium Priority Fixes
- MEDIUM-1: Replace ! with ?? to handle unknown ProcessingState
- MEDIUM-2: Escape LIKE wildcards in search queries
- MEDIUM-4: Display StreamBuilder errors instead of treating as empty
- MEDIUM-8: Add tooltips to all IconButtons for accessibility
- Add doc comments to public database APIs

## Testing
- Add regression tests for CRITICAL-1 and CRITICAL-2
- All 9 existing tests pass

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Dustin-Mike Jens Hähnel
2026-08-16 19:04:54 +02:00
co-authored by Claude Haiku 4.5
parent b5ab7bd9dd
commit 4fa8d12fa0
11 changed files with 156 additions and 30 deletions
+17 -7
View File
@@ -44,11 +44,15 @@ Future<int> scanAndroidMediaStore(
var coverPath = prev?.coverPath;
if (coverPath == null) {
final art = await audioQuery.queryArtwork(s.id, ArtworkType.AUDIO, size: 512);
if (art != null && art.isNotEmpty) {
final f = File(p.join(covers.path, '$id.img'));
await f.writeAsBytes(art);
coverPath = f.path;
try {
final art = await audioQuery.queryArtwork(s.id, ArtworkType.AUDIO, size: 512);
if (art != null && art.isNotEmpty) {
final f = File(p.join(covers.path, '$id.img'));
await f.writeAsBytes(art);
coverPath = f.path;
}
} catch (_) {
// Kaputtes Cover verzögert nicht den Scan.
}
}
@@ -63,11 +67,17 @@ Future<int> scanAndroidMediaStore(
dateAddedMs: prev?.dateAddedMs ??
(s.dateAdded != null ? s.dateAdded! * 1000 : now),
updatedAtMs: now,
deleted: const Value(false),
));
onProgress?.call(++done, songs.length);
++done;
if (done % 50 == 0 || done == songs.length) {
onProgress?.call(done, songs.length);
}
}
await db.upsertSongs(companions);
await db.markMissing(livePaths, now);
if (livePaths.isNotEmpty) {
await db.markMissing(now);
}
return companions.length;
}