Skip to content

Commit

Permalink
topotato: tiny error reporting improvement
Browse files Browse the repository at this point in the history
Actually indicate what went wrong in `.iface_to()`

Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Sep 6, 2024
1 parent c2fa718 commit b383fb1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions topotato/toponom.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,15 @@ def iface_to(self, other: str) -> "LinkIface":
get the *one* interfaces of this node that goes to "other"
If there is more than one interface towards `other`, this throws
`AssertionError`.
an exception.
"""
ifaces = self.ifaces_to(other)
assert len(ifaces) == 1
if not ifaces:
raise ValueError(f"{self.name!r} has no link to {other!r}")
if len(ifaces) > 1:
raise ValueError(
f"{self.name!r} has {len(ifaces)} links to {other!r}, expected exactly 1"
)
return ifaces[0]

def iface_peer(self, other: str, via=Optional["LAN"]) -> "LinkIface":
Expand Down

0 comments on commit b383fb1

Please sign in to comment.