From 826eafbc8613ac10dc4d513bd2fabc642a46b36a Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 27 Mar 2024 16:34:24 +0000 Subject: [PATCH] Add UnknownStation Exception --- agenda/trip.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/agenda/trip.py b/agenda/trip.py index 06fbf2a..db148e9 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -9,6 +9,12 @@ from agenda import travel from agenda.types import StrDict, Trip +class UnknownStation(Exception): + """Unknown station.""" + + pass + + def load_travel(travel_type: str, data_dir: str) -> list[StrDict]: """Read flight and train journeys.""" items = travel.parse_yaml(travel_type + "s", data_dir) @@ -24,8 +30,10 @@ def load_trains(data_dir: str) -> list[StrDict]: by_name = {station["name"]: station for station in stations} for train in trains: - assert train["from"] in by_name - assert train["to"] in by_name + if train["from"] not in by_name: + raise UnknownStation(train["from"]) + if train["to"] not in by_name: + raise UnknownStation(train["to"]) train["from_station"] = by_name[train["from"]] train["to_station"] = by_name[train["to"]]