@@ -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,9 @@ impl Graph {
8787 . iter ( )
8888 . map ( |name| match self . get_visible_module_by_name ( name) {
8989 Ok ( module) => Ok ( module) ,
90- Err ( GrimpError :: ModuleNotPresent ( _) ) => {
90+ Err ( ModuleNotPresent ( _) ) => {
9191 Err ( GrimpError :: NoSuchContainer ( name. into ( ) ) ) ?
9292 }
93- _ => panic ! ( "unexpected error parsing containers" ) ,
9493 } )
9594 . collect :: < Result < HashSet < _ > , GrimpError > > ( )
9695 }
@@ -124,8 +123,7 @@ impl Graph {
124123 . filter_map ( |name| match self . get_visible_module_by_name ( & name) {
125124 Ok ( module) => Some ( module. token ( ) ) ,
126125 // TODO(peter) Error here? Or silently continue (backwards compatibility?)
127- Err ( GrimpError :: ModuleNotPresent ( _) ) => None ,
128- _ => panic ! ( "unexpected error parsing levels" ) ,
126+ Err ( ModuleNotPresent ( _) ) => None ,
129127 } )
130128 . collect :: < FxHashSet < _ > > ( ) ;
131129
@@ -207,11 +205,7 @@ impl Graph {
207205 }
208206
209207 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- }
208+ self . get_visible_module_by_name ( name) . is_ok ( )
215209 }
216210
217211 #[ pyo3( signature = ( module, is_squashed = false ) ) ]
@@ -301,7 +295,7 @@ impl Graph {
301295 pub fn find_children ( & self , module : & str ) -> PyResult < HashSet < String > > {
302296 let module = self
303297 . get_module_by_name ( module)
304- . ok_or ( GrimpError :: ModuleNotPresent ( module. to_owned ( ) ) ) ?;
298+ . ok_or ( ModuleNotPresent ( module. to_owned ( ) ) ) ?;
305299 Ok ( self
306300 . get_module_children ( module. token ( ) )
307301 . visible ( )
@@ -312,7 +306,7 @@ impl Graph {
312306 pub fn find_descendants ( & self , module : & str ) -> PyResult < HashSet < String > > {
313307 let module = self
314308 . get_module_by_name ( module)
315- . ok_or ( GrimpError :: ModuleNotPresent ( module. to_owned ( ) ) ) ?;
309+ . ok_or ( ModuleNotPresent ( module. to_owned ( ) ) ) ?;
316310 Ok ( self
317311 . get_module_descendants ( module. token ( ) )
318312 . visible ( )
0 commit comments