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: <name>`
instead of `<name>: <message>`. 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.
This commit is contained in:
splitsec2 authored and GitHub committed 2026-10-20 00:59:54 -04:00
1 parent 93f58caf7a
commit 65dbf42a86
2 files changed
+5 -4

No files matched your search

+3 -2
View File
@@ -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}"
+2 -2
View File
@@ -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)