@@ -219,9 +219,23 @@ fn load_world_graph_data() -> anyhow::Result<WorldGraphData> {
219219 let mut hub_specs = HashMap :: new ( ) ;
220220
221221 // Parse hub IDs from names (e.g., "H01" -> 1, "H02" -> 2) to preserve stable IDs
222+ let mut used_hub_ids = std:: collections:: HashSet :: new ( ) ;
222223 for ( hub_name, hub_spec) in & world_graph. hubs {
223224 if hub_name. starts_with ( 'H' ) && hub_name. len ( ) >= 2 {
224225 if let Ok ( hub_num) = hub_name[ 1 ..] . parse :: < u16 > ( ) {
226+ if hub_num == 0 {
227+ return Err ( anyhow:: anyhow!(
228+ "hub IDs must be greater than 0: {}" ,
229+ hub_name
230+ ) ) ;
231+ }
232+
233+ // Check for duplicate hub IDs
234+ if used_hub_ids. contains ( & hub_num) {
235+ return Err ( anyhow:: anyhow!( "duplicate hub ID found: {}" , hub_num) ) ;
236+ }
237+ used_hub_ids. insert ( hub_num) ;
238+
225239 let hub_id = HubId ( hub_num) ;
226240 hub_names. insert ( hub_name. clone ( ) , hub_id) ;
227241 hub_specs. insert ( hub_id, hub_spec. clone ( ) ) ;
@@ -241,10 +255,24 @@ fn load_world_graph_data() -> anyhow::Result<WorldGraphData> {
241255
242256 // Create a mapping from link names to RouteIds by parsing the numeric suffix (e.g., "L01" -> 1, "L02" -> 2)
243257 let mut link_to_route_id = HashMap :: new ( ) ;
258+ let mut used_route_ids = std:: collections:: HashSet :: new ( ) ;
244259
245260 for ( link_name, _) in & world_graph. links {
246261 if link_name. starts_with ( 'L' ) && link_name. len ( ) >= 2 {
247262 if let Ok ( route_num) = link_name[ 1 ..] . parse :: < u16 > ( ) {
263+ if route_num == 0 {
264+ return Err ( anyhow:: anyhow!(
265+ "route IDs must be greater than 0: {}" ,
266+ link_name
267+ ) ) ;
268+ }
269+
270+ // Check for duplicate route IDs
271+ if used_route_ids. contains ( & route_num) {
272+ return Err ( anyhow:: anyhow!( "duplicate route ID found: {}" , route_num) ) ;
273+ }
274+ used_route_ids. insert ( route_num) ;
275+
248276 let route_id = RouteId ( route_num) ;
249277 link_to_route_id. insert ( link_name, route_id) ;
250278 } else {
0 commit comments