@@ -3,14 +3,14 @@ use std::fmt::Write;
3
3
use std:: path:: PathBuf ;
4
4
use std:: sync:: Arc ;
5
5
6
+ use anyhow:: { anyhow, Context as _, Error , Result } ;
6
7
use docs_rs:: db:: { self , add_path_into_database, Pool , PoolClient } ;
7
8
use docs_rs:: repositories:: RepositoryStatsUpdater ;
8
9
use docs_rs:: utils:: { remove_crate_priority, set_crate_priority} ;
9
10
use docs_rs:: {
10
11
BuildQueue , Config , Context , DocBuilder , Index , Metrics , PackageKind , RustwideBuilder , Server ,
11
12
Storage ,
12
13
} ;
13
- use failure:: { err_msg, Error , ResultExt } ;
14
14
use once_cell:: sync:: OnceCell ;
15
15
use structopt:: StructOpt ;
16
16
use strum:: VariantNames ;
@@ -21,12 +21,14 @@ pub fn main() {
21
21
22
22
if let Err ( err) = CommandLine :: from_args ( ) . handle_args ( ) {
23
23
let mut msg = format ! ( "Error: {}" , err) ;
24
- for cause in err. iter_causes ( ) {
24
+ for cause in err. chain ( ) {
25
25
write ! ( msg, "\n \n Caused by:\n {}" , cause) . unwrap ( ) ;
26
26
}
27
27
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) ;
30
32
}
31
33
std:: process:: exit ( 1 ) ;
32
34
}
@@ -108,7 +110,7 @@ enum CommandLine {
108
110
}
109
111
110
112
impl CommandLine {
111
- pub fn handle_args ( self ) -> Result < ( ) , Error > {
113
+ pub fn handle_args ( self ) -> Result < ( ) > {
112
114
let ctx = BinContext :: new ( ) ;
113
115
114
116
match self {
@@ -166,7 +168,7 @@ enum QueueSubcommand {
166
168
}
167
169
168
170
impl QueueSubcommand {
169
- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
171
+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
170
172
match self {
171
173
Self :: Add {
172
174
crate_name,
@@ -205,7 +207,7 @@ enum PrioritySubcommand {
205
207
}
206
208
207
209
impl PrioritySubcommand {
208
- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
210
+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
209
211
match self {
210
212
Self :: Set { pattern, priority } => {
211
213
set_crate_priority ( & mut * ctx. conn ( ) ?, & pattern, priority)
@@ -239,7 +241,7 @@ struct Build {
239
241
}
240
242
241
243
impl Build {
242
- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
244
+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
243
245
self . subcommand . handle_args ( ctx, self . skip_if_exists )
244
246
}
245
247
}
@@ -286,10 +288,10 @@ enum BuildSubcommand {
286
288
}
287
289
288
290
impl 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 < ( ) > {
290
292
let docbuilder = DocBuilder :: new ( ctx. config ( ) ?, ctx. pool ( ) ?, ctx. build_queue ( ) ?) ;
291
293
292
- let rustwide_builder = || -> Result < RustwideBuilder , Error > {
294
+ let rustwide_builder = || -> Result < RustwideBuilder > {
293
295
let mut builder = RustwideBuilder :: init ( & ctx) ?;
294
296
builder. set_skip_build_if_exists ( skip_if_exists) ;
295
297
Ok ( builder)
@@ -317,9 +319,10 @@ impl BuildSubcommand {
317
319
let registry_url = ctx. config ( ) ?. registry_url . clone ( ) ;
318
320
builder
319
321
. 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" ) ) ?,
321
324
& crate_version
322
- . ok_or_else ( || err_msg ( "must specify version if not local" ) ) ?,
325
+ . with_context ( || anyhow ! ( "must specify version if not local" ) ) ?,
323
326
registry_url
324
327
. as_ref ( )
325
328
. map ( |s| PackageKind :: Registry ( s. as_str ( ) ) )
@@ -412,7 +415,7 @@ enum DatabaseSubcommand {
412
415
}
413
416
414
417
impl DatabaseSubcommand {
415
- pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
418
+ pub fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
416
419
match self {
417
420
Self :: Migrate { version } => {
418
421
db:: migrate ( version, & mut * ctx. conn ( ) ?)
@@ -482,7 +485,7 @@ enum BlacklistSubcommand {
482
485
}
483
486
484
487
impl BlacklistSubcommand {
485
- fn handle_args ( self , ctx : BinContext ) -> Result < ( ) , Error > {
488
+ fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
486
489
let mut conn = & mut * ctx. conn ( ) ?;
487
490
match self {
488
491
Self :: List => {
@@ -545,14 +548,14 @@ impl BinContext {
545
548
}
546
549
}
547
550
548
- fn conn ( & self ) -> Result < PoolClient , Error > {
551
+ fn conn ( & self ) -> Result < PoolClient > {
549
552
Ok ( self . pool ( ) ?. get ( ) ?)
550
553
}
551
554
}
552
555
553
556
macro_rules! lazy {
554
557
( $( fn $name: ident( $self: ident) -> $type: ty = $init: expr) ;+ $( ; ) ? ) => {
555
- $( fn $name( & $self) -> Result <Arc <$type>, Error > {
558
+ $( fn $name( & $self) -> Result <Arc <$type>> {
556
559
Ok ( $self
557
560
. $name
558
561
. get_or_try_init:: <_, Error >( || Ok ( Arc :: new( $init) ) ) ?
@@ -591,7 +594,7 @@ impl Context for BinContext {
591
594
} ;
592
595
}
593
596
594
- fn pool ( & self ) -> Result < Pool , Error > {
597
+ fn pool ( & self ) -> Result < Pool > {
595
598
Ok ( self
596
599
. pool
597
600
. get_or_try_init :: < _ , Error > ( || Ok ( Pool :: new ( & * self . config ( ) ?, self . metrics ( ) ?) ?) ) ?
0 commit comments