fix(worker): a corrupt/unreadable album no longer aborts the whole scan

Live-testing #9 surfaced a pre-existing gap: one truncated file mutagen chokes
on ("file said 4 bytes, read 0 bytes") raised out of _process_album and aborted
the entire library scan (worklist abandoned). Now scan_chunk catches a per-album
error, rolls back, logs it, counts it as skipped, marks the item done, and
continues — so a single bad file can't block the rest of the library.

worker tests: new case asserts a corrupt album is skipped while a good one still
imports (and captures its on-disk trackNames).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-14 13:00:02 +02:00
parent dcf0bb0696
commit 9a95c33b7e
2 changed files with 34 additions and 1 deletions
+11 -1
View File
@@ -169,7 +169,17 @@ def scan_chunk(conn: psycopg.Connection, resolver, probe: AudioProbe, browser,
imported = skipped = 0
browsed: set[str] = set() # artists whose discography we've populated this chunk
for item_id, artist_name, album_folder, album_path in items:
outcome = _process_album(conn, resolver, probe, browser, artist_name, album_folder, album_path, browsed)
try:
outcome = _process_album(conn, resolver, probe, browser, artist_name, album_folder, album_path, browsed)
except Exception as e:
# a single unreadable/corrupt album (e.g. a truncated file mutagen chokes on) must
# not abort the whole scan — skip it, mark it done, and keep going.
try:
conn.rollback()
except Exception:
pass
print(f"scan: skipping {artist_name}/{album_folder}: {e}", flush=True)
outcome = "skipped"
if outcome == "imported":
imported += 1
elif outcome == "skipped":