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