From c0e4d2aa85f2e380ee93cf18d3cb204225dde6b5 Mon Sep 17 00:00:00 2001 From: dschlueter Date: Wed, 18 Feb 2026 06:18:12 +0100 Subject: [PATCH] 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 --- src/musiksammlung/cli.py | 14 +++++++++++++- tests/test_ripper.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/musiksammlung/cli.py b/src/musiksammlung/cli.py index 5dba9c4..bcbe1b7 100644 --- a/src/musiksammlung/cli.py +++ b/src/musiksammlung/cli.py @@ -6,6 +6,7 @@ import json import logging from pathlib import Path +import httpx import typer 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.""" if barcode: typer.echo(f"MusicBrainz-Suche nach Barcode {barcode}...") - return lookup_by_barcode(barcode) + try: + 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: text = from_text.read_text(encoding="utf-8") typer.echo(f"Text-Datei geladen ({len(text)} Zeichen). LLM-Parsing...") diff --git a/tests/test_ripper.py b/tests/test_ripper.py index dfd2b15..3666d09 100644 --- a/tests/test_ripper.py +++ b/tests/test_ripper.py @@ -1,7 +1,7 @@ """Tests für den CD-Ripper.""" from pathlib import Path -from unittest.mock import MagicMock, call, patch +from unittest.mock import MagicMock, patch from musiksammlung.config import AudioFormat from musiksammlung.models import Album, Disc, Track