@@ -8,7 +8,7 @@ use error_stack::{Report, Result, ResultExt};
88use fast_glob:: glob_match;
99use ignore:: { DirEntry , WalkBuilder , WalkParallel , WalkState } ;
1010use rayon:: iter:: { IntoParallelIterator , ParallelIterator } ;
11- use tracing:: { instrument, warn } ;
11+ use tracing:: instrument;
1212
1313use crate :: {
1414 cache:: Cache ,
@@ -178,9 +178,17 @@ impl<'a> ProjectBuilder<'a> {
178178 }
179179
180180 fn build_project_from_entry_types ( & mut self , entry_types : Vec < EntryType > ) -> Result < Project , Error > {
181- let ( project_files, packages, vendored_gems, directory_codeowners, teams) : ( Vec < _ > , Vec < _ > , Vec < _ > , Vec < _ > , Vec < _ > ) = entry_types
181+ type Accumulator = (
182+ Vec < ProjectFile > ,
183+ Vec < Package > ,
184+ Vec < VendoredGem > ,
185+ Vec < DirectoryCodeownersFile > ,
186+ Vec < Team > ,
187+ ) ;
188+
189+ let ( project_files, packages, vendored_gems, directory_codeowners, teams) : Accumulator = entry_types
182190 . into_par_iter ( )
183- . fold (
191+ . try_fold (
184192 || {
185193 (
186194 Vec :: < ProjectFile > :: with_capacity ( INITIAL_VECTOR_CAPACITY ) ,
@@ -197,18 +205,20 @@ impl<'a> ProjectBuilder<'a> {
197205 }
198206 EntryType :: Directory ( absolute_path, relative_path) => {
199207 if relative_path. parent ( ) == Some ( Path :: new ( & self . config . vendored_gems_path ) ) {
200- if let Some ( file_name) = relative_path. file_name ( ) {
201- gems . push ( VendoredGem {
202- path : absolute_path ,
203- name : file_name . to_string_lossy ( ) . to_string ( ) ,
204- } ) ;
205- } else {
206- warn ! ( "Vendored gem path without file name: {:?}" , relative_path ) ;
207- }
208+ let file_name = relative_path. file_name ( ) . ok_or_else ( || {
209+ error_stack :: report! ( Error :: Io )
210+ . attach_printable ( format ! ( "Vendored gem path has no file name: {}" , relative_path . display ( ) ) )
211+ } ) ? ;
212+ gems . push ( VendoredGem {
213+ path : absolute_path ,
214+ name : file_name . to_string_lossy ( ) . to_string ( ) ,
215+ } ) ;
208216 }
209217 }
210218 EntryType :: RubyPackage ( absolute_path, relative_path) => {
211- match ruby_package_owner ( & absolute_path) {
219+ match ruby_package_owner ( & absolute_path)
220+ . attach_printable_lazy ( || format ! ( "Failed to read ruby package: {}" , absolute_path. display( ) ) )
221+ {
212222 Ok ( Some ( owner) ) => {
213223 pkgs. push ( Package {
214224 path : relative_path. clone ( ) ,
@@ -217,13 +227,13 @@ impl<'a> ProjectBuilder<'a> {
217227 } ) ;
218228 }
219229 Ok ( None ) => { /* No owner, do nothing */ }
220- Err ( e) => {
221- warn ! ( "Error reading ruby package owner for {:?}: {:?}" , absolute_path, e) ;
222- }
230+ Err ( e) => return Err ( e) ,
223231 }
224232 }
225233 EntryType :: JavascriptPackage ( absolute_path, relative_path) => {
226- match javascript_package_owner ( & absolute_path) {
234+ match javascript_package_owner ( & absolute_path)
235+ . attach_printable_lazy ( || format ! ( "Failed to read javascript package: {}" , absolute_path. display( ) ) )
236+ {
227237 Ok ( Some ( owner) ) => {
228238 pkgs. push ( Package {
229239 path : relative_path. clone ( ) ,
@@ -232,47 +242,41 @@ impl<'a> ProjectBuilder<'a> {
232242 } ) ;
233243 }
234244 Ok ( None ) => { /* No owner, do nothing */ }
235- Err ( e) => {
236- warn ! ( "Error reading javascript package owner for {:?}: {:?}" , absolute_path, e) ;
237- }
245+ Err ( e) => return Err ( e) ,
238246 }
239247 }
240- EntryType :: CodeownerFile ( absolute_path, relative_path) => match std:: fs:: read_to_string ( & absolute_path) {
241- Ok ( owner) => {
242- let owner = owner. trim ( ) . to_owned ( ) ;
243- codeowners. push ( DirectoryCodeownersFile {
244- path : relative_path. clone ( ) ,
245- owner,
246- } ) ;
247- }
248- Err ( e) => {
249- warn ! ( "Error reading codeowner file for {:?}: {:?}" , absolute_path, e) ;
250- }
251- } ,
252- EntryType :: TeamFile ( absolute_path, _relative_path) => match Team :: from_team_file_path ( absolute_path) {
253- Ok ( team) => {
254- team_files. push ( team) ;
255- }
256- Err ( e) => {
257- warn ! ( "Error building team from team file path: {}" , e) ;
258- }
259- } ,
248+ EntryType :: CodeownerFile ( absolute_path, relative_path) => {
249+ let owner = std:: fs:: read_to_string ( & absolute_path)
250+ . change_context ( Error :: Io )
251+ . attach_printable_lazy ( || format ! ( "Failed to read codeowner file: {}" , absolute_path. display( ) ) ) ?;
252+ let owner = owner. trim ( ) . to_owned ( ) ;
253+ codeowners. push ( DirectoryCodeownersFile {
254+ path : relative_path. clone ( ) ,
255+ owner,
256+ } ) ;
257+ }
258+ EntryType :: TeamFile ( absolute_path, _relative_path) => {
259+ let team = Team :: from_team_file_path ( absolute_path. clone ( ) )
260+ . change_context ( Error :: Io )
261+ . attach_printable_lazy ( || format ! ( "Failed to read team file: {}" , absolute_path. display( ) ) ) ?;
262+ team_files. push ( team) ;
263+ }
260264 EntryType :: NullEntry ( ) => { }
261265 }
262- ( project_files, pkgs, gems, codeowners, team_files)
266+ Ok ( ( project_files, pkgs, gems, codeowners, team_files) )
263267 } ,
264268 )
265- . reduce (
269+ . try_reduce (
266270 || ( Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ,
267271 |mut acc, item| {
268272 acc. 0 . extend ( item. 0 ) ;
269273 acc. 1 . extend ( item. 1 ) ;
270274 acc. 2 . extend ( item. 2 ) ;
271275 acc. 3 . extend ( item. 3 ) ;
272276 acc. 4 . extend ( item. 4 ) ;
273- acc
277+ Ok ( acc)
274278 } ,
275- ) ;
279+ ) ? ;
276280 let teams_by_name = teams
277281 . iter ( )
278282 . flat_map ( |team| vec ! [ ( team. name. clone( ) , team. clone( ) ) , ( team. github_team. clone( ) , team. clone( ) ) ] )
0 commit comments