fix: show clean error message when MusicBrainz barcode lookup fails
Catch ValueError (barcode not found) and httpx.HTTPError (network error) in _scan_to_album and print a user-friendly message with hint instead of a raw Python traceback. Also remove unused `call` import in test_ripper.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b70127e838
commit
c0e4d2aa85
2 changed files with 14 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import json
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import httpx
|
||||||
import typer
|
import typer
|
||||||
from mutagen import File as MutagenFile
|
from mutagen import File as MutagenFile
|
||||||
|
|
||||||
|
|
@ -46,7 +47,18 @@ def _scan_to_album(
|
||||||
"""Gemeinsame Scan-Logik: Barcode, Text-Datei, Vision-LLM oder OCR+LLM."""
|
"""Gemeinsame Scan-Logik: Barcode, Text-Datei, Vision-LLM oder OCR+LLM."""
|
||||||
if barcode:
|
if barcode:
|
||||||
typer.echo(f"MusicBrainz-Suche nach Barcode {barcode}...")
|
typer.echo(f"MusicBrainz-Suche nach Barcode {barcode}...")
|
||||||
|
try:
|
||||||
return lookup_by_barcode(barcode)
|
return lookup_by_barcode(barcode)
|
||||||
|
except ValueError as e:
|
||||||
|
typer.echo(f"Fehler: {e}", err=True)
|
||||||
|
typer.echo(
|
||||||
|
"Tipp: Barcode prüfen oder Metadaten per --from-text / --vision ermitteln.",
|
||||||
|
err=True,
|
||||||
|
)
|
||||||
|
raise typer.Exit(1)
|
||||||
|
except httpx.HTTPError as e:
|
||||||
|
typer.echo(f"Netzwerkfehler bei MusicBrainz-Abfrage: {e}", err=True)
|
||||||
|
raise typer.Exit(1)
|
||||||
elif from_text:
|
elif from_text:
|
||||||
text = from_text.read_text(encoding="utf-8")
|
text = from_text.read_text(encoding="utf-8")
|
||||||
typer.echo(f"Text-Datei geladen ({len(text)} Zeichen). LLM-Parsing...")
|
typer.echo(f"Text-Datei geladen ({len(text)} Zeichen). LLM-Parsing...")
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"""Tests für den CD-Ripper."""
|
"""Tests für den CD-Ripper."""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock, call, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from musiksammlung.config import AudioFormat
|
from musiksammlung.config import AudioFormat
|
||||||
from musiksammlung.models import Album, Disc, Track
|
from musiksammlung.models import Album, Disc, Track
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue