File tree 2 files changed +23
-10
lines changed
2 files changed +23
-10
lines changed Original file line number Diff line number Diff line change 1
1
use super :: CrateTrait ;
2
2
use crate :: { PrepareError , Workspace } ;
3
- use anyhow:: Context as _;
3
+ use anyhow:: { anyhow , Context as _} ;
4
4
use flate2:: read:: GzDecoder ;
5
5
use log:: info;
6
6
use std:: fs:: File ;
@@ -163,12 +163,22 @@ impl CrateTrait for RegistryCrate {
163
163
std:: fs:: create_dir_all ( parent) ?;
164
164
}
165
165
166
- workspace
166
+ match workspace
167
167
. http_client ( )
168
168
. get ( self . fetch_url ( workspace) ?)
169
169
. send ( ) ?
170
- . error_for_status ( ) ?
171
- . write_to ( & mut BufWriter :: new ( File :: create ( & local) ?) ) ?;
170
+ . error_for_status ( )
171
+ {
172
+ Ok ( resonse) => resonse,
173
+ Err ( err) => {
174
+ return Err ( anyhow ! ( err) . context ( PrepareError :: RegistryOperationFailed {
175
+ action : "fetch" ,
176
+ krate : self . name . clone ( ) ,
177
+ version : self . version . clone ( ) ,
178
+ } ) )
179
+ }
180
+ }
181
+ . write_to ( & mut BufWriter :: new ( File :: create ( & local) ?) ) ?;
172
182
173
183
Ok ( ( ) )
174
184
}
@@ -194,7 +204,8 @@ impl CrateTrait for RegistryCrate {
194
204
) ;
195
205
if let Err ( err) = unpack_without_first_dir ( & mut tar, dest) {
196
206
let _ = crate :: utils:: remove_dir_all ( dest) ;
197
- Err ( err. context ( PrepareError :: UnpackFailed {
207
+ Err ( err. context ( PrepareError :: RegistryOperationFailed {
208
+ action : "unpack" ,
198
209
krate : self . name . clone ( ) ,
199
210
version : self . version . clone ( ) ,
200
211
} ) )
Original file line number Diff line number Diff line change @@ -424,12 +424,14 @@ pub enum PrepareError {
424
424
/// repo url
425
425
url : String ,
426
426
} ,
427
- /// failed to unpack crate
428
- #[ error( "failed to unpack {krate} version {version}" ) ]
429
- UnpackFailed {
430
- /// the crates name
427
+ /// failed to fetch/unpack a crate from a registry
428
+ #[ error( "failed to {action} {krate} version {version}" ) ]
429
+ RegistryOperationFailed {
430
+ /// the action that failed
431
+ action : & ' static str ,
432
+ /// the name of the crate
431
433
krate : String ,
432
- /// the crates version
434
+ /// the version of the crate
433
435
version : String ,
434
436
} ,
435
437
}
You can’t perform that action at this time.
0 commit comments