@@ -120,29 +120,36 @@ pub struct MuxConfig {
120120impl MuxConfig {
121121 /// Returns the env, actual path, and internal path to use for the file
122122 /// loader
123- pub fn loader_env ( & self ) -> Option < ( String , String , String ) > {
124- self . loader . as_ref ( ) . and_then ( |loader| match loader {
125- MuxKeysLoader :: File ( path_buf) => {
126- if !path_buf. try_exists ( ) . is_ok_and ( |exists| exists) {
127- panic ! ( "path doesn't exist: {:?}" , path_buf) ;
128- }
123+ pub fn loader_env ( & self ) -> eyre:: Result < Option < ( String , String , String ) > > {
124+ let Some ( loader) = self . loader . as_ref ( ) else {
125+ return Ok ( None ) ;
126+ } ;
129127
130- if !path_buf
131- . file_name ( )
132- . is_some_and ( |name| name. to_string_lossy ( ) . to_lowercase ( ) . ends_with ( ".json" ) )
133- {
134- panic ! ( "file doesn't have a .json extension" ) ;
135- }
128+ match loader {
129+ MuxKeysLoader :: File ( path_buf) => {
130+ ensure ! (
131+ path_buf. try_exists( ) . is_ok_and( |exists| exists) ,
132+ "path doesn't exist: {:?}" ,
133+ path_buf
134+ ) ;
135+
136+ ensure ! (
137+ path_buf. extension( ) . is_some_and( |ext| ext == "json" ) ,
138+ "file doesn't have a .json extension: {:?}" ,
139+ path_buf
140+ ) ;
141+
142+ let Some ( path) = path_buf. to_str ( ) else {
143+ bail ! ( "invalid path: {:?}" , path_buf) ;
144+ } ;
136145
137- let path =
138- path_buf. to_str ( ) . unwrap_or_else ( || panic ! ( "invalid path: {:?}" , path_buf) ) ;
139146 let internal_path = get_mux_path ( & self . id ) ;
140147
141- Some ( ( get_mux_env ( & self . id ) , path. to_owned ( ) , internal_path) )
148+ Ok ( Some ( ( get_mux_env ( & self . id ) , path. to_owned ( ) , internal_path) ) )
142149 }
143- MuxKeysLoader :: HTTP { .. } => None ,
144- MuxKeysLoader :: Registry { .. } => None ,
145- } )
150+ MuxKeysLoader :: HTTP { .. } => Ok ( None ) ,
151+ MuxKeysLoader :: Registry { .. } => Ok ( None ) ,
152+ }
146153 }
147154}
148155
0 commit comments