@@ -20,8 +20,8 @@ macro_rules! get_item_from {
2020 ( $oid: expr, $repo: expr, $typs: ident) => {
2121 git_repository:: hash:: ObjectId :: from( $oid)
2222 . 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 ) ) ) ?
2525 } ;
2626}
2727
@@ -170,7 +170,7 @@ pub fn get_function_history(
170170 // elem.0.signed_duration_since(date)
171171 } )
172172 . map ( |elem| elem. hash . clone ( ) )
173- . unwrap_to_error_sync ( "no commits found" ) ?
173+ . unwrap_to_error ( "no commits found" ) ?
174174 }
175175 Filter :: Author ( _)
176176 | Filter :: AuthorEmail ( _)
@@ -310,9 +310,9 @@ fn sender(
310310 name : & str ,
311311 langs : Language ,
312312 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" ) ?;
316316 traverse_tree ( & tree, repo, name, "" , langs, file)
317317}
318318
@@ -323,12 +323,12 @@ fn traverse_tree(
323323 path : & str ,
324324 langs : Language ,
325325 filetype : & FileFilterType ,
326- ) -> Result < Vec < FileType > , Box < dyn std :: error :: Error > > {
326+ ) -> Result < Vec < FileType > , String > {
327327 let treee_iter = tree. iter ( ) ;
328328 let mut files: Vec < ( String , String ) > = Vec :: new ( ) ;
329329 let mut ret = Vec :: new ( ) ;
330330 for i in treee_iter {
331- let i = i?;
331+ let i = i. map_err ( |_| "failed to get tree entry" ) ?;
332332 match & i. mode ( ) {
333333 objs:: tree:: EntryMode :: Tree => {
334334 let new = get_item_from ! ( i. oid( ) , & repo, try_into_tree) ;
@@ -414,8 +414,8 @@ fn traverse_tree(
414414 }
415415 } ,
416416 }
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" ) ?;
419419 let blob = objref. into_blob ( ) ;
420420 if let Some ( blob) = blob {
421421 files. push ( ( file, String :: from_utf8_lossy ( blob. data ) . to_string ( ) ) ) ;
@@ -531,10 +531,10 @@ fn find_function_in_file_with_commit(
531531 fc : & str ,
532532 name : & str ,
533533 langs : Language ,
534- ) -> Result < FileType , Box < dyn Error > > {
534+ ) -> Result < FileType , String > {
535535 let file = match langs {
536536 Language :: Rust => {
537- let functions = rust:: find_function_in_file ( fc, name) ?;
537+ let functions = rust:: find_function_in_file ( fc, name) ?;
538538 FileType :: Rust ( RustFile :: new ( file_path. to_string ( ) , functions) )
539539 }
540540 // #[cfg(feature = "c_lang")]
@@ -544,24 +544,25 @@ fn find_function_in_file_with_commit(
544544 // }
545545 #[ cfg( feature = "unstable" ) ]
546546 Language :: Go => {
547- let functions = languages:: go:: find_function_in_file ( fc, name) ?;
547+ let functions = languages:: go:: find_function_in_file ( fc, name) ?;
548548 FileType :: Go ( GoFile :: new ( file_path. to_string ( ) , functions) )
549549 }
550550 Language :: Python => {
551- let functions = languages:: python:: find_function_in_file ( fc, name) ?;
551+ let functions = languages:: python:: find_function_in_file ( fc, name) ?;
552552 FileType :: Python ( PythonFile :: new ( file_path. to_string ( ) , functions) )
553553 }
554554 Language :: Ruby => {
555- let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
555+ let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
556556 FileType :: Ruby ( RubyFile :: new ( file_path. to_string ( ) , functions) )
557557 }
558558 Language :: UMPL => {
559- let functions = languages:: umpl:: find_function_in_file ( fc, name) ?;
559+ let functions = languages:: umpl:: find_function_in_file ( fc, name) ?;
560560 FileType :: UMPL ( UMPLFile :: new ( file_path. to_string ( ) , functions) )
561561 }
562562 Language :: All => match file_path. split ( '.' ) . last ( ) {
563563 Some ( "rs" ) => {
564- let functions = rust:: find_function_in_file ( fc, name) ?;
564+
565+ let functions = rust:: find_function_in_file ( fc, name) ?;
565566 FileType :: Rust ( RustFile :: new ( file_path. to_string ( ) , functions) )
566567 }
567568 // #[cfg(feature = "c_lang")]
@@ -570,16 +571,16 @@ fn find_function_in_file_with_commit(
570571 // FileType::C(CFile::new(file_path.to_string(), functions))
571572 // }
572573 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) ?;
574575 FileType :: Python ( PythonFile :: new ( file_path. to_string ( ) , functions) )
575576 }
576577 #[ cfg( feature = "unstable" ) ]
577578 Some ( "go" ) => {
578- let functions = languages:: go:: find_function_in_file ( fc, name) ?;
579+ let functions = languages:: go:: find_function_in_file ( fc, name) ?;
579580 FileType :: Go ( GoFile :: new ( file_path. to_string ( ) , functions) )
580581 }
581582 Some ( "rb" ) => {
582- let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
583+ let functions = languages:: ruby:: find_function_in_file ( fc, name) ?;
583584 FileType :: Ruby ( RubyFile :: new ( file_path. to_string ( ) , functions) )
584585 }
585586 _ => Err ( "unknown file type" ) ?,
@@ -613,16 +614,13 @@ fn ends_with_cmp_no_case(filename: &str, file_ext: &str) -> bool {
613614}
614615
615616trait 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 > ;
618618}
619619
620620impl < 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) )
626624 }
627625}
628626
0 commit comments