File tree Expand file tree Collapse file tree 2 files changed +23
-10
lines changed Expand file tree Collapse file tree 2 files changed +23
-10
lines changed Original file line number Diff line number Diff line change 11use  super :: CrateTrait ; 
22use  crate :: { PrepareError ,  Workspace } ; 
3- use  anyhow:: Context  as  _; 
3+ use  anyhow:: { anyhow ,   Context  as  _} ; 
44use  flate2:: read:: GzDecoder ; 
55use  log:: info; 
66use  std:: fs:: File ; 
@@ -163,12 +163,22 @@ impl CrateTrait for RegistryCrate {
163163            std:: fs:: create_dir_all ( parent) ?; 
164164        } 
165165
166-         workspace
166+         match   workspace
167167            . http_client ( ) 
168168            . get ( self . fetch_url ( workspace) ?) 
169169            . 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) ?) ) ?; 
172182
173183        Ok ( ( ) ) 
174184    } 
@@ -194,7 +204,8 @@ impl CrateTrait for RegistryCrate {
194204        ) ; 
195205        if  let  Err ( err)  = unpack_without_first_dir ( & mut  tar,  dest)  { 
196206            let  _ = crate :: utils:: remove_dir_all ( dest) ; 
197-             Err ( err. context ( PrepareError :: UnpackFailed  { 
207+             Err ( err. context ( PrepareError :: RegistryOperationFailed  { 
208+                 action :  "unpack" , 
198209                krate :  self . name . clone ( ) , 
199210                version :  self . version . clone ( ) , 
200211            } ) ) 
Original file line number Diff line number Diff line change @@ -424,12 +424,14 @@ pub enum PrepareError {
424424        /// repo url 
425425url :  String , 
426426    } , 
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 
431433krate :  String , 
432-         /// the crates  version 
434+         /// the version of the crate  
433435version :  String , 
434436    } , 
435437} 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments