From 65dbf42a86aff710760e3e3f4d11e2ebfb720d12 Mon Sep 17 00:00:00 2001 From: splitsec2 <35583321+splitsec2@users.noreply.github.com> Date: Mon, 19 Oct 2026 22:59:54 -0600 Subject: [PATCH] fix(release-search): report a ValueError from a source as that source's error (#1433) Kept small on purpose so it's easy to review. This is the same kind of small fix as the ones in #1429 to #1432, so see the question in #1429 about separate PRs versus combined. I'm sending them separately until I hear otherwise. In `search_source_releases` the `except ValueError` comes before the branch that handles the operational errors, and `ValueError` is in that tuple. A `ValueError` from `build_release_search_plan` or `source.search()` is therefore reported as `Unknown source: ` instead of `: `. The only `ValueError` meant for that branch is the one `get_source` raises for a name that isn't registered, so that call now has its own `try` and the rest goes back to the operational errors branch. The failure test already covered `OSError` and `RuntimeError`, so I added `ValueError` to it, and that case fails on current `main`. Ruff, basedpyright and `tests/core` pass. The one red check is the existing clock-dependent test `test_a_queued_torrent_asks_for_a_grace_once`, which fails on any runner that booted recently. It is fixed in #1426 and is not caused by this change. --- shelfmark/core/release_search.py | 5 +++-- tests/core/test_release_search.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shelfmark/core/release_search.py b/shelfmark/core/release_search.py index 44064483..be082e25 100644 --- a/shelfmark/core/release_search.py +++ b/shelfmark/core/release_search.py @@ -47,7 +47,10 @@ def search_source_releases( try: source = get_source(source_name) + except ValueError: + return None, [], f"Unknown source: {source_name}" + try: plan = build_release_search_plan( search_book, languages=languages, @@ -84,8 +87,6 @@ def search_source_releases( releases = source.search( search_book, plan, expand_search=expand_search, content_type=content_type ) - except ValueError: - return None, [], f"Unknown source: {source_name}" except (SourceUnavailableError, *_OPERATIONAL_ERRORS) as exc: logger.warning("Release search failed for source %s: %s", source_name, exc) return None, [], f"{source_name}: {exc!s}" diff --git a/tests/core/test_release_search.py b/tests/core/test_release_search.py index 3434d28a..2755966b 100644 --- a/tests/core/test_release_search.py +++ b/tests/core/test_release_search.py @@ -54,8 +54,8 @@ def test_unknown_source_returns_error_tuple(monkeypatch: pytest.MonkeyPatch) -> @pytest.mark.parametrize( "exc", - [SourceUnavailableError("down"), OSError("boom"), RuntimeError("bad")], - ids=["unavailable", "oserror", "runtime"], + [SourceUnavailableError("down"), OSError("boom"), RuntimeError("bad"), ValueError("odd")], + ids=["unavailable", "oserror", "runtime", "valueerror"], ) def test_source_failures_become_messages(monkeypatch: pytest.MonkeyPatch, exc: Exception) -> None: src = _Source(error=exc)