@@ -3,14 +3,14 @@ use std::fmt::Write;
33use std:: path:: PathBuf ;
44use std:: sync:: Arc ;
55
6+ use anyhow:: { anyhow, Context as _, Error , Result } ;
67use docs_rs:: db:: { self , add_path_into_database, Pool , PoolClient } ;
78use docs_rs:: repositories:: RepositoryStatsUpdater ;
89use docs_rs:: utils:: { remove_crate_priority, set_crate_priority} ;
910use docs_rs:: {
1011 BuildQueue , Config , Context , DocBuilder , Index , Metrics , PackageKind , RustwideBuilder , Server ,
1112 Storage ,
1213} ;
13- use failure:: { err_msg, Error , ResultExt } ;
1414use once_cell:: sync:: OnceCell ;
1515use structopt:: StructOpt ;
1616use strum:: VariantNames ;
@@ -21,12 +21,14 @@ pub fn main() {
2121
2222 if let Err ( err) = CommandLine :: from_args ( ) . handle_args ( ) {
2323 let mut msg = format ! ( "Error: {}" , err) ;
24- for cause in err. iter_causes ( ) {
24+ for cause in err. chain ( ) {
2525 write ! ( msg, "\n \n Caused by:\n {}" , cause) . unwrap ( ) ;
2626 }
2727 eprintln ! ( "{}" , msg) ;
28- if !err. backtrace ( ) . is_empty ( ) {
29- eprintln ! ( "\n Stack backtrace:\n {}" , err. backtrace( ) ) ;
28+
29+ let backtrace = err. backtrace ( ) . to_string ( ) ;
30+ if !backtrace. is_empty ( ) {
31+ eprintln ! ( "\n Stack backtrace:\n {}" , backtrace) ;
3032 }
3133 std:: process:: exit ( 1 ) ;
3234 }
@@ -108,7 +110,7 @@ enum CommandLine {
108110}
109111
110112impl CommandLine {
111- pub fn handle_args ( self ) -> Result < ( ) , Error > {
113+ pub fn handle_args ( self ) -> Result < ( ) > {
112114 let ctx = BinContext :: new ( ) ;
113115
114116 match self {
@@ -166,7 +168,7 @@ enum QueueSubcommand {
166168}
167169
168170impl QueueSubcommand {
169- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
171+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
170172 match self {
171173 Self :: Add {
172174 crate_name,
@@ -205,7 +207,7 @@ enum PrioritySubcommand {
205207}
206208
207209impl PrioritySubcommand {
208- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
210+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
209211 match self {
210212 Self :: Set { pattern, priority } => {
211213 set_crate_priority ( & mut * ctx. conn ( ) ?, & pattern, priority)
@@ -239,7 +241,7 @@ struct Build {
239241}
240242
241243impl Build {
242- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
244+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
243245 self . subcommand . handle_args ( ctx, self . skip_if_exists )
244246 }
245247}
@@ -286,10 +288,10 @@ enum BuildSubcommand {
286288}
287289
288290impl BuildSubcommand {
289- pub fn handle_args ( self , ctx : BinContext , skip_if_exists : bool ) -> Result < ( ) , Error > {
291+ pub fn handle_args ( self , ctx : BinContext , skip_if_exists : bool ) -> Result < ( ) > {
290292 let docbuilder = DocBuilder :: new ( ctx. config ( ) ?, ctx. pool ( ) ?, ctx. build_queue ( ) ?) ;
291293
292- let rustwide_builder = || -> Result < RustwideBuilder , Error > {
294+ let rustwide_builder = || -> Result < RustwideBuilder > {
293295 let mut builder = RustwideBuilder :: init ( & ctx) ?;
294296 builder. set_skip_build_if_exists ( skip_if_exists) ;
295297 Ok ( builder)
@@ -317,9 +319,10 @@ impl BuildSubcommand {
317319 let registry_url = ctx. config ( ) ?. registry_url . clone ( ) ;
318320 builder
319321 . build_package (
320- & crate_name. ok_or_else ( || err_msg ( "must specify name if not local" ) ) ?,
322+ & crate_name
323+ . with_context ( || anyhow ! ( "must specify name if not local" ) ) ?,
321324 & crate_version
322- . ok_or_else ( || err_msg ( "must specify version if not local" ) ) ?,
325+ . with_context ( || anyhow ! ( "must specify version if not local" ) ) ?,
323326 registry_url
324327 . as_ref ( )
325328 . map ( |s| PackageKind :: Registry ( s. as_str ( ) ) )
@@ -412,7 +415,7 @@ enum DatabaseSubcommand {
412415}
413416
414417impl DatabaseSubcommand {
415- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
418+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
416419 match self {
417420 Self :: Migrate { version } => {
418421 db:: migrate ( version, & mut * ctx. conn ( ) ?)
@@ -482,7 +485,7 @@ enum BlacklistSubcommand {
482485}
483486
484487impl BlacklistSubcommand {
485- fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
488+ fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
486489 let mut conn = & mut * ctx. conn ( ) ?;
487490 match self {
488491 Self :: List => {
@@ -545,14 +548,14 @@ impl BinContext {
545548 }
546549 }
547550
548- fn conn ( & self ) -> Result < PoolClient , Error > {
551+ fn conn ( & self ) -> Result < PoolClient > {
549552 Ok ( self . pool ( ) ?. get ( ) ?)
550553 }
551554}
552555
553556macro_rules! lazy {
554557 ( $( fn $name: ident( $self: ident) -> $type: ty = $init: expr) ;+ $( ; ) ? ) => {
555- $( fn $name( & $self) -> Result <Arc <$type>, Error > {
558+ $( fn $name( & $self) -> Result <Arc <$type>> {
556559 Ok ( $self
557560 . $name
558561 . get_or_try_init:: <_, Error >( || Ok ( Arc :: new( $init) ) ) ?
@@ -591,7 +594,7 @@ impl Context for BinContext {
591594 } ;
592595 }
593596
594- fn pool ( & self ) -> Result < Pool , Error > {
597+ fn pool ( & self ) -> Result < Pool > {
595598 Ok ( self
596599 . pool
597600 . get_or_try_init :: < _ , Error > ( || Ok ( Pool :: new ( & * self . config ( ) ?, self . metrics ( ) ?) ?) ) ?
0 commit comments