@@ -49,15 +49,7 @@ impl CommandExecutor {
4949 args : & [ & str ] ,
5050 working_dir : Option < & Path > ,
5151 ) -> Result < CommandResult , CommandError > {
52- // Check if working directory exists before attempting to run the command
53- // This provides a clearer error message than the generic "No such file or directory"
54- if let Some ( dir) = working_dir {
55- if !dir. exists ( ) {
56- return Err ( CommandError :: WorkingDirectoryNotFound {
57- working_dir : dir. to_path_buf ( ) ,
58- } ) ;
59- }
60- }
52+ Self :: validate_working_directory ( working_dir) ?;
6153
6254 let mut command = Command :: new ( cmd) ;
6355 let command_display = format ! ( "{} {}" , cmd, args. join( " " ) ) ;
@@ -128,6 +120,21 @@ impl CommandExecutor {
128120
129121 Ok ( CommandResult :: new ( output. status , stdout, stderr) )
130122 }
123+
124+ /// Validates that the working directory exists if provided.
125+ ///
126+ /// This provides a clearer error message than the generic "No such file or directory"
127+ /// that would be returned by the OS.
128+ fn validate_working_directory ( working_dir : Option < & Path > ) -> Result < ( ) , CommandError > {
129+ if let Some ( dir) = working_dir {
130+ if !dir. exists ( ) {
131+ return Err ( CommandError :: WorkingDirectoryNotFound {
132+ working_dir : dir. to_path_buf ( ) ,
133+ } ) ;
134+ }
135+ }
136+ Ok ( ( ) )
137+ }
131138}
132139
133140#[ cfg( test) ]
0 commit comments