@@ -197,14 +197,19 @@ struct ProjectIter {
197197 it : walkdir:: IntoIter ,
198198}
199199
200+ pub enum Red {
201+ IOError ( :: std:: io:: Error ) ,
202+ WalkdirError ( walkdir:: Error ) ,
203+ }
204+
200205impl Iterator for ProjectIter {
201- type Item = Project ;
206+ type Item = Result < Project , Red > ;
202207
203208 fn next ( & mut self ) -> Option < Self :: Item > {
204209 loop {
205210 let entry: walkdir:: DirEntry = match self . it . next ( ) {
206211 None => return None ,
207- Some ( Err ( _ ) ) => continue ,
212+ Some ( Err ( e ) ) => return Some ( Err ( Red :: WalkdirError ( e ) ) ) ,
208213 Some ( Ok ( entry) ) => entry,
209214 } ;
210215 if !entry. file_type ( ) . is_dir ( ) {
@@ -215,15 +220,17 @@ impl Iterator for ProjectIter {
215220 continue ;
216221 }
217222 let rd = match entry. path ( ) . read_dir ( ) {
218- Err ( _ ) => continue ,
223+ Err ( e ) => return Some ( Err ( Red :: IOError ( e ) ) ) ,
219224 Ok ( rd) => rd,
220225 } ;
221- for dir_entry in rd. filter_map ( |rd| rd. ok ( ) ) {
222- let file_name = match dir_entry. file_name ( ) . into_string ( ) {
223- Err ( _) => continue ,
224- Ok ( file_name) => file_name,
226+ // intentionally ignoring errors while iterating the ReadDir
227+ // can't return them because we'll lose the context of where we are
228+ for dir_entry in rd. filter_map ( |rd| rd. ok ( ) ) . map ( |de| de. file_name ( ) ) {
229+ let file_name = match dir_entry. to_str ( ) {
230+ None => continue ,
231+ Some ( file_name) => file_name,
225232 } ;
226- let p_type = match file_name. as_str ( ) {
233+ let p_type = match file_name {
227234 FILE_CARGO_TOML => Some ( ProjectType :: Cargo ) ,
228235 FILE_PACKAGE_JSON => Some ( ProjectType :: Node ) ,
229236 FILE_ASSEMBLY_CSHARP => Some ( ProjectType :: Unity ) ,
@@ -243,17 +250,17 @@ impl Iterator for ProjectIter {
243250 } ;
244251 if let Some ( project_type) = p_type {
245252 self . it . skip_current_dir ( ) ;
246- return Some ( Project {
253+ return Some ( Ok ( Project {
247254 project_type,
248255 path : entry. path ( ) . to_path_buf ( ) ,
249- } ) ;
256+ } ) ) ;
250257 }
251258 }
252259 }
253260 }
254261}
255262
256- pub fn scan < P : AsRef < path:: Path > > ( p : & P ) -> impl Iterator < Item = Project > {
263+ pub fn scan < P : AsRef < path:: Path > > ( p : & P ) -> impl Iterator < Item = Result < Project , Red > > {
257264 ProjectIter {
258265 it : walkdir:: WalkDir :: new ( p)
259266 . follow_links ( SYMLINK_FOLLOW )
0 commit comments