@@ -14,7 +14,7 @@ use std::sync::{LazyLock, RwLock};
1414use string_interner:: backend:: StringBackend ;
1515use string_interner:: { DefaultSymbol , StringInterner } ;
1616
17- use crate :: errors:: { GrimpError , GrimpResult } ;
17+ use crate :: errors:: { GrimpError , GrimpResult , ModuleNotPresent } ;
1818use crate :: graph:: higher_order_queries:: { Level , PackageDependency } ;
1919use crate :: module_expressions:: ModuleExpression ;
2020
@@ -73,10 +73,10 @@ pub struct Graph {
7373}
7474
7575impl Graph {
76- fn get_visible_module_by_name ( & self , name : & str ) -> Result < & Module , GrimpError > {
76+ fn get_visible_module_by_name ( & self , name : & str ) -> Result < & Module , ModuleNotPresent > {
7777 self . get_module_by_name ( name)
7878 . filter ( |m| !m. is_invisible ( ) )
79- . ok_or ( GrimpError :: ModuleNotPresent ( name. to_owned ( ) ) )
79+ . ok_or ( ModuleNotPresent ( name. to_owned ( ) ) )
8080 }
8181
8282 fn parse_containers (
@@ -87,10 +87,7 @@ impl Graph {
8787 . iter ( )
8888 . map ( |name| match self . get_visible_module_by_name ( name) {
8989 Ok ( module) => Ok ( module) ,
90- Err ( GrimpError :: ModuleNotPresent ( _) ) => {
91- Err ( GrimpError :: NoSuchContainer ( name. into ( ) ) ) ?
92- }
93- _ => panic ! ( "unexpected error parsing containers" ) ,
90+ Err ( ModuleNotPresent ( _) ) => Err ( GrimpError :: NoSuchContainer ( name. into ( ) ) ) ?,
9491 } )
9592 . collect :: < Result < HashSet < _ > , GrimpError > > ( )
9693 }
@@ -124,8 +121,7 @@ impl Graph {
124121 . filter_map ( |name| match self . get_visible_module_by_name ( & name) {
125122 Ok ( module) => Some ( module. token ( ) ) ,
126123 // TODO(peter) Error here? Or silently continue (backwards compatibility?)
127- Err ( GrimpError :: ModuleNotPresent ( _) ) => None ,
128- _ => panic ! ( "unexpected error parsing levels" ) ,
124+ Err ( ModuleNotPresent ( _) ) => None ,
129125 } )
130126 . collect :: < FxHashSet < _ > > ( ) ;
131127
@@ -207,11 +203,7 @@ impl Graph {
207203 }
208204
209205 pub fn contains_module ( & self , name : & str ) -> bool {
210- match self . get_visible_module_by_name ( name) {
211- Ok ( _) => true ,
212- Err ( GrimpError :: ModuleNotPresent ( _) ) => false ,
213- _ => panic ! ( "unexpected error checking for module existence" ) ,
214- }
206+ self . get_visible_module_by_name ( name) . is_ok ( )
215207 }
216208
217209 #[ pyo3( signature = ( module, is_squashed = false ) ) ]
@@ -301,7 +293,7 @@ impl Graph {
301293 pub fn find_children ( & self , module : & str ) -> PyResult < HashSet < String > > {
302294 let module = self
303295 . get_module_by_name ( module)
304- . ok_or ( GrimpError :: ModuleNotPresent ( module. to_owned ( ) ) ) ?;
296+ . ok_or ( ModuleNotPresent ( module. to_owned ( ) ) ) ?;
305297 Ok ( self
306298 . get_module_children ( module. token ( ) )
307299 . visible ( )
@@ -312,7 +304,7 @@ impl Graph {
312304 pub fn find_descendants ( & self , module : & str ) -> PyResult < HashSet < String > > {
313305 let module = self
314306 . get_module_by_name ( module)
315- . ok_or ( GrimpError :: ModuleNotPresent ( module. to_owned ( ) ) ) ?;
307+ . ok_or ( ModuleNotPresent ( module. to_owned ( ) ) ) ?;
316308 Ok ( self
317309 . get_module_descendants ( module. token ( ) )
318310 . visible ( )
0 commit comments