fix(validate): narrow bare except to ImportError in psutil port-collision check
The original except Exception silently disabled port collision detection for any runtime error — not just a missing package. Now only ImportError degrades gracefully; real psutil failures propagate.
This commit is contained in:
@@ -16,8 +16,11 @@ from ipaddress import IPv4Address, IPv4Network
|
|||||||
from typing import Any, Callable, Literal
|
from typing import Any, Callable, Literal
|
||||||
|
|
||||||
from decnet.fleet import all_service_names
|
from decnet.fleet import all_service_names
|
||||||
|
from decnet.logging import get_logger
|
||||||
from decnet.services.registry import get_service
|
from decnet.services.registry import get_service
|
||||||
|
|
||||||
|
log = get_logger("topology.validate")
|
||||||
|
|
||||||
Severity = Literal["error", "warning"]
|
Severity = Literal["error", "warning"]
|
||||||
|
|
||||||
|
|
||||||
@@ -373,7 +376,8 @@ def check_no_host_port_collision(h: dict[str, Any]) -> list[ValidationIssue]:
|
|||||||
for c in psutil.net_connections(kind="inet")
|
for c in psutil.net_connections(kind="inet")
|
||||||
if c.status == psutil.CONN_LISTEN and c.laddr
|
if c.status == psutil.CONN_LISTEN and c.laddr
|
||||||
}
|
}
|
||||||
except Exception:
|
except ImportError:
|
||||||
|
log.warning("psutil not available; skipping host port collision check")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
issues: list[ValidationIssue] = []
|
issues: list[ValidationIssue] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user