fix(client): default_gateway never raises
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uc9V1v7iXruubpoLiSE24M
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user