Skip to content

Commit

Permalink
Give more useful comment for user to correct topology
Browse files Browse the repository at this point in the history
when a node name used in link does not correspond to listed
node names, Bad link msg was thrown without info on which link
causes the problem.
This change gives additional info on link and catch the user error
more cleanly.

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
  • Loading branch information
EstherLerouzic committed Dec 12, 2019
1 parent d483802 commit 5e22590
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gnpy/core/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from pathlib import Path
from difflib import get_close_matches
from gnpy.core.utils import silent_remove
from gnpy.core.exceptions import NetworkTopologyError
import time

all_rows = lambda sh, start=0: (sh.row(x) for x in range(start, sh.nrows))
Expand Down Expand Up @@ -509,9 +510,12 @@ def parse_excel(input_filename):
all_cities = Counter(n.city for n in nodes)
if len(all_cities) != len(nodes):
raise ValueError(f'Duplicate city: {all_cities}')
if any(ln.from_city not in all_cities or
ln.to_city not in all_cities for ln in links):
raise ValueError(f'Bad link.')
bad_links = []
for lnk in links:
if lnk.from_city not in all_cities or lnk.to_city not in all_cities:
bad_links.append([lnk.from_city, lnk.to_city])
if bad_links:
raise NetworkTopologyError(f'Bad link(s): {bad_links}.')

return nodes, links, eqpts

Expand Down

0 comments on commit 5e22590

Please sign in to comment.