File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -152,3 +152,12 @@ Feature: Find WordPress installs on the filesystem
152152 """
153153 0
154154 """
155+
156+ Scenario : Invalid path specified
157+ Given an empty directory
158+
159+ When I try `wp find foo`
160+ Then STDERR should be:
161+ """
162+ Error: Invalid path specified.
163+ """
Original file line number Diff line number Diff line change @@ -141,6 +141,9 @@ class Find_Command {
141141 public function __invoke ( $ args , $ assoc_args ) {
142142 list ( $ path ) = $ args ;
143143 $ this ->base_path = realpath ( $ path );
144+ if ( ! $ this ->base_path ) {
145+ WP_CLI ::error ( 'Invalid path specified. ' );
146+ }
144147 $ this ->skip_ignored_paths = Utils \get_flag_value ( $ assoc_args , 'skip-ignored-paths ' );
145148 $ this ->max_depth = Utils \get_flag_value ( $ assoc_args , 'max_depth ' , false );
146149 $ this ->verbose = Utils \get_flag_value ( $ assoc_args , 'verbose ' );
@@ -196,7 +199,12 @@ private function recurse_directory( $path ) {
196199 // Check all files and directories of this path to recurse
197200 // into subdirectories.
198201 $ this ->log ( "Recusing into {$ path }" );
199- $ iterator = new RecursiveDirectoryIterator ( $ path , FilesystemIterator::SKIP_DOTS );
202+ try {
203+ $ iterator = new RecursiveDirectoryIterator ( $ path , FilesystemIterator::SKIP_DOTS );
204+ } catch ( Exception $ e ) {
205+ $ this ->log ( "Exception thrown ' {$ e ->getMessage ()}'. Skipping recursion into {$ path }" );
206+ return ;
207+ }
200208 foreach ( $ iterator as $ file_info ) {
201209 if ( $ file_info ->isDir () ) {
202210 $ this ->current_depth ++;
You can’t perform that action at this time.
0 commit comments