@@ -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,22 @@ 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 ) . attach_printable ( format ! (
210+ "Vendored gem path has no file name: {}" ,
211+ relative_path. display( )
212+ ) )
213+ } ) ?;
214+ gems. push ( VendoredGem {
215+ path : absolute_path,
216+ name : file_name. to_string_lossy ( ) . to_string ( ) ,
217+ } ) ;
208218 }
209219 }
210220 EntryType :: RubyPackage ( absolute_path, relative_path) => {
211- match ruby_package_owner ( & absolute_path) {
221+ match ruby_package_owner ( & absolute_path)
222+ . attach_printable_lazy ( || format ! ( "Failed to read ruby package: {}" , absolute_path. display( ) ) )
223+ {
212224 Ok ( Some ( owner) ) => {
213225 pkgs. push ( Package {
214226 path : relative_path. clone ( ) ,
@@ -217,13 +229,13 @@ impl<'a> ProjectBuilder<'a> {
217229 } ) ;
218230 }
219231 Ok ( None ) => { /* No owner, do nothing */ }
220- Err ( e) => {
221- warn ! ( "Error reading ruby package owner for {:?}: {:?}" , absolute_path, e) ;
222- }
232+ Err ( e) => return Err ( e) ,
223233 }
224234 }
225235 EntryType :: JavascriptPackage ( absolute_path, relative_path) => {
226- match javascript_package_owner ( & absolute_path) {
236+ match javascript_package_owner ( & absolute_path)
237+ . attach_printable_lazy ( || format ! ( "Failed to read javascript package: {}" , absolute_path. display( ) ) )
238+ {
227239 Ok ( Some ( owner) ) => {
228240 pkgs. push ( Package {
229241 path : relative_path. clone ( ) ,
@@ -232,47 +244,41 @@ impl<'a> ProjectBuilder<'a> {
232244 } ) ;
233245 }
234246 Ok ( None ) => { /* No owner, do nothing */ }
235- Err ( e) => {
236- warn ! ( "Error reading javascript package owner for {:?}: {:?}" , absolute_path, e) ;
237- }
247+ Err ( e) => return Err ( e) ,
238248 }
239249 }
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- } ,
250+ EntryType :: CodeownerFile ( absolute_path, relative_path) => {
251+ let owner = std:: fs:: read_to_string ( & absolute_path)
252+ . change_context ( Error :: Io )
253+ . attach_printable_lazy ( || format ! ( "Failed to read codeowner file: {}" , absolute_path. display( ) ) ) ?;
254+ let owner = owner. trim ( ) . to_owned ( ) ;
255+ codeowners. push ( DirectoryCodeownersFile {
256+ path : relative_path. clone ( ) ,
257+ owner,
258+ } ) ;
259+ }
260+ EntryType :: TeamFile ( absolute_path, _relative_path) => {
261+ let team = Team :: from_team_file_path ( absolute_path. clone ( ) )
262+ . change_context ( Error :: Io )
263+ . attach_printable_lazy ( || format ! ( "Failed to read team file: {}" , absolute_path. display( ) ) ) ?;
264+ team_files. push ( team) ;
265+ }
260266 EntryType :: NullEntry ( ) => { }
261267 }
262- ( project_files, pkgs, gems, codeowners, team_files)
268+ Ok ( ( project_files, pkgs, gems, codeowners, team_files) )
263269 } ,
264270 )
265- . reduce (
271+ . try_reduce (
266272 || ( Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ,
267273 |mut acc, item| {
268274 acc. 0 . extend ( item. 0 ) ;
269275 acc. 1 . extend ( item. 1 ) ;
270276 acc. 2 . extend ( item. 2 ) ;
271277 acc. 3 . extend ( item. 3 ) ;
272278 acc. 4 . extend ( item. 4 ) ;
273- acc
279+ Ok ( acc)
274280 } ,
275- ) ;
281+ ) ? ;
276282 let teams_by_name = teams
277283 . iter ( )
278284 . flat_map ( |team| vec ! [ ( team. name. clone( ) , team. clone( ) ) , ( team. github_team. clone( ) , team. clone( ) ) ] )
0 commit comments