From a5e0dcea52a266f38a3efbf605363ca3923b2b6d Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 7 Oct 2026 11:38:23 -0400 Subject: [PATCH] fix: report network errors for gh: specs instead of a traceback Only HTTPError was caught. A DNS or connection failure raises URLError and printed a full traceback. Assisted-by: ClaudeCode:claude-fable-5-1 ClaudeCode:claude-fable-5-1 --- src/repo_review/__main__.py | 4 ++++ tests/test_remote_path.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/repo_review/__main__.py b/src/repo_review/__main__.py index f2d5740..b392339 100644 --- a/src/repo_review/__main__.py +++ b/src/repo_review/__main__.py @@ -304,6 +304,10 @@ def _remote_path_processor(package: str) -> Path | GHPath: rich.print(f"[red][bold]Error[/bold] accessing {e.url}", file=sys.stderr) rich.print(f"[red]{e}", file=sys.stderr) raise SystemExit(1) from None + except urllib.error.URLError as e: + rich.print(f"[red][bold]Error[/bold] accessing {package}", file=sys.stderr) + rich.print(f"[red]{e.reason}", file=sys.stderr) + raise SystemExit(1) from None def main(args: list[str] | None = None) -> None: diff --git a/tests/test_remote_path.py b/tests/test_remote_path.py index ecb273d..592e75a 100644 --- a/tests/test_remote_path.py +++ b/tests/test_remote_path.py @@ -1,4 +1,5 @@ import json +import urllib.error from pathlib import Path import pytest @@ -55,3 +56,18 @@ def spy(package: object) -> object: assert seen == ["gh:org/repo@main:src/pkg"] assert isinstance(seen[0], str) + + +def test_remote_path_offline( + monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] +) -> None: + def fake_open(url: str) -> str: # noqa: ARG001 + msg = "Name or service not known" + raise urllib.error.URLError(msg) + + monkeypatch.setattr(GHPath, "open_url", staticmethod(fake_open)) + with pytest.raises(SystemExit) as excinfo: + _remote_path_processor("gh:org/repo") + + assert excinfo.value.code == 1 + assert "Name or service not known" in capsys.readouterr().err