From ad19d2596a1f1f623770a936b9bd82175cdf662e Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Mon, 21 Sep 2026 09:17:48 -0400 Subject: [PATCH] fix(client): default_gateway never raises Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Uc9V1v7iXruubpoLiSE24M --- hbd/client/gateway.py | 2 +- tests/test_gateway.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hbd/client/gateway.py b/hbd/client/gateway.py index 39cd24f..db15f57 100644 --- a/hbd/client/gateway.py +++ b/hbd/client/gateway.py @@ -98,6 +98,6 @@ async def default_gateway(family: str) -> Optional[str]: return parse_macos_route(await _run(cmd)) if sys.platform == "win32": return parse_windows_route(await _run(["route", "print", "-4" if v4 else "-6"]), family) - except (OSError, asyncio.TimeoutError, ValueError): + except Exception: return None return None diff --git a/tests/test_gateway.py b/tests/test_gateway.py index 167d0a4..a156646 100644 --- a/tests/test_gateway.py +++ b/tests/test_gateway.py @@ -1,3 +1,6 @@ +import asyncio +import struct + from hbd.client import gateway PROC_V4 = ( @@ -62,3 +65,11 @@ def test_windows_v4_lowest_metric(): def test_windows_v6(): assert gateway.parse_windows_route(WIN_V6, "ipv6") == "fe80::1" + + +def test_default_gateway_never_raises_on_parser_error(monkeypatch): + """default_gateway catches all exceptions; never raises even if parser fails.""" + monkeypatch.setattr("sys.platform", "linux") + monkeypatch.setattr(gateway, "parse_proc_route_v4", lambda _: (_ for _ in ()).throw(struct.error)) + result = asyncio.run(gateway.default_gateway("ipv4")) + assert result is None