@@ -20,8 +20,8 @@ macro_rules! get_item_from {
20
20
( $oid: expr, $repo: expr, $typs: ident) => {
21
21
git_repository:: hash:: ObjectId :: from( $oid)
22
22
. attach( & $repo)
23
- . object( ) ?
24
- . $typs( ) ?
23
+ . object( ) . map_err ( |_| "Could not find object" ) ?
24
+ . $typs( ) . map_err ( |_| format! ( "Could not find {} from object" , stringify! ( $typs ) ) ) ?
25
25
} ;
26
26
}
27
27
@@ -170,7 +170,7 @@ pub fn get_function_history(
170
170
// elem.0.signed_duration_since(date)
171
171
} )
172
172
. map ( |elem| elem. hash . clone ( ) )
173
- . unwrap_to_error_sync ( "no commits found" ) ?
173
+ . unwrap_to_error ( "no commits found" ) ?
174
174
}
175
175
Filter :: Author ( _)
176
176
| Filter :: AuthorEmail ( _)
@@ -310,9 +310,9 @@ fn sender(
310
310
name : & str ,
311
311
langs : Language ,
312
312
file : & FileFilterType ,
313
- ) -> Result < Vec < FileType > , Box < dyn std :: error :: Error > > {
314
- let object = repo. find_object ( id) ?;
315
- let tree = object. try_into_tree ( ) ?;
313
+ ) -> Result < Vec < FileType > , String > {
314
+ let object = repo. find_object ( id) . map_err ( |_| "failed to find object" ) ?;
315
+ let tree = object. try_into_tree ( ) . map_err ( |_| "failed to find tree" ) ?;
316
316
traverse_tree ( & tree, repo, name, "" , langs, file)
317
317
}
318
318
@@ -323,12 +323,12 @@ fn traverse_tree(
323
323
path : & str ,
324
324
langs : Language ,
325
325
filetype : & FileFilterType ,
326
- ) -> Result < Vec < FileType > , Box < dyn std :: error :: Error > > {
326
+ ) -> Result < Vec < FileType > , String > {
327
327
let treee_iter = tree. iter ( ) ;
328
328
let mut files: Vec < ( String , String ) > = Vec :: new ( ) ;
329
329
let mut ret = Vec :: new ( ) ;
330
330
for i in treee_iter {
331
- let i = i?;
331
+ let i = i. map_err ( |_| "failed to get tree entry" ) ?;
332
332
match & i. mode ( ) {
333
333
objs:: tree:: EntryMode :: Tree => {
334
334
let new = get_item_from ! ( i. oid( ) , & repo, try_into_tree) ;
@@ -414,8 +414,8 @@ fn traverse_tree(
414
414
}
415
415
} ,
416
416
}
417
- let obh = repo. find_object ( i. oid ( ) ) ?;
418
- let objref = objs:: ObjectRef :: from_bytes ( obh. kind , & obh. data ) ?;
417
+ let obh = repo. find_object ( i. oid ( ) ) . map_err ( |_| "failed to find object" ) ?;
418
+ let objref = objs:: ObjectRef :: from_bytes ( obh. kind , & obh. data ) . map_err ( |_| "failed to get object ref" ) ?;
419
419
let blob = objref. into_blob ( ) ;
420
420
if let Some ( blob) = blob {
421
421
files. push ( ( file, String :: from_utf8_lossy ( blob. data ) . to_string ( ) ) ) ;
@@ -531,10 +531,10 @@ fn find_function_in_file_with_commit(
531
531
fc : & str ,
532
532
name : & str ,
533
533
langs : Language ,
534
- ) -> Result < FileType , Box < dyn Error > > {
534
+ ) -> Result < FileType , String > {
535
535
let file = match langs {
536
536
Language :: Rust => {
537
- let functions = rust:: find_function_in_file ( fc, name) ?;
537
+ let functions = rust:: find_function_in_file ( fc, name) ?;
538
538
FileType :: Rust ( RustFile :: new ( file_path. to_string ( ) , functions) )
539
539
}
540
540
// #[cfg(feature = "c_lang")]
@@ -544,24 +544,25 @@ fn find_function_in_file_with_commit(
544
544
// }
545
545
#[ cfg( feature = "unstable" ) ]
546
546
Language :: Go => {
547
- let functions = languages:: go:: find_function_in_file ( fc, name) ?;
547
+ let functions = languages:: go:: find_function_in_file ( fc, name) ?;
548
548
FileType :: Go ( GoFile :: new ( file_path. to_string ( ) , functions) )
549
549
}
550
550
Language :: Python => {
551
- let functions = languages:: python:: find_function_in_file ( fc, name) ?;
551
+ let functions = languages:: python:: find_function_in_file ( fc, name) ?;
552
552
FileType :: Python ( PythonFile :: new ( file_path. to_string ( ) , functions) )
553
553
}
554
554
Language :: Ruby => {
555
- let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
555
+ let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
556
556
FileType :: Ruby ( RubyFile :: new ( file_path. to_string ( ) , functions) )
557
557
}
558
558
Language :: UMPL => {
559
- let functions = languages:: umpl:: find_function_in_file ( fc, name) ?;
559
+ let functions = languages:: umpl:: find_function_in_file ( fc, name) ?;
560
560
FileType :: UMPL ( UMPLFile :: new ( file_path. to_string ( ) , functions) )
561
561
}
562
562
Language :: All => match file_path. split ( '.' ) . last ( ) {
563
563
Some ( "rs" ) => {
564
- let functions = rust:: find_function_in_file ( fc, name) ?;
564
+
565
+ let functions = rust:: find_function_in_file ( fc, name) ?;
565
566
FileType :: Rust ( RustFile :: new ( file_path. to_string ( ) , functions) )
566
567
}
567
568
// #[cfg(feature = "c_lang")]
@@ -570,16 +571,16 @@ fn find_function_in_file_with_commit(
570
571
// FileType::C(CFile::new(file_path.to_string(), functions))
571
572
// }
572
573
Some ( "py" | "pyw" ) => {
573
- let functions = languages:: python:: find_function_in_file ( fc, name) ?;
574
+ let functions = languages:: python:: find_function_in_file ( fc, name) ?;
574
575
FileType :: Python ( PythonFile :: new ( file_path. to_string ( ) , functions) )
575
576
}
576
577
#[ cfg( feature = "unstable" ) ]
577
578
Some ( "go" ) => {
578
- let functions = languages:: go:: find_function_in_file ( fc, name) ?;
579
+ let functions = languages:: go:: find_function_in_file ( fc, name) ?;
579
580
FileType :: Go ( GoFile :: new ( file_path. to_string ( ) , functions) )
580
581
}
581
582
Some ( "rb" ) => {
582
- let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
583
+ let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
583
584
FileType :: Ruby ( RubyFile :: new ( file_path. to_string ( ) , functions) )
584
585
}
585
586
_ => Err ( "unknown file type" ) ?,
@@ -613,16 +614,13 @@ fn ends_with_cmp_no_case(filename: &str, file_ext: &str) -> bool {
613
614
}
614
615
615
616
trait UnwrapToError < T > {
616
- fn unwrap_to_error_sync ( self , message : & str ) -> Result < T , Box < dyn Error + Send + Sync > > ;
617
- fn unwrap_to_error ( self , message : & str ) -> Result < T , Box < dyn Error > > ;
617
+ fn unwrap_to_error ( self , message : & str ) -> Result < T , String > ;
618
618
}
619
619
620
620
impl < T > UnwrapToError < T > for Option < T > {
621
- fn unwrap_to_error_sync ( self , message : & str ) -> Result < T , Box < dyn Error + Send + Sync > > {
622
- self . map_or_else ( || Err ( message) ?, |val| Ok ( val) )
623
- }
624
- fn unwrap_to_error ( self , message : & str ) -> Result < T , Box < dyn Error > > {
625
- self . map_or_else ( || Err ( message) ?, |val| Ok ( val) )
621
+
622
+ fn unwrap_to_error ( self , message : & str ) -> Result < T , String > {
623
+ self . map_or_else ( || Err ( message. to_string ( ) ) , |val| Ok ( val) )
626
624
}
627
625
}
628
626
0 commit comments