Improve the error message when a crate cannot be found
authorAbhishek Chanda <abhishek.chanda@emc.com>
Wed, 12 Aug 2015 06:21:06 +0000 (23:21 -0700)
committerAbhishek Chanda <abhishek.chanda@emc.com>
Wed, 12 Aug 2015 18:49:51 +0000 (11:49 -0700)
Closes #1892

src/cargo/ops/registry.rs
src/crates-io/lib.rs

index ee2e78f5252617765bf55853b292f953eb602eff..57ea235d7611aa909ce499e9be99bb574b1c3837 100644 (file)
@@ -281,7 +281,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
             try!(config.shell().status("Owner", format!("adding `{:?}` to `{}`",
                                                         v, name)));
             try!(registry.add_owners(&name, &v).map_err(|e| {
-                human(format!("failed to add owners: {}", e))
+                human(format!("failed to add owners to crate {}: {}", name, e))
             }));
         }
         None => {}
@@ -293,7 +293,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
             try!(config.shell().status("Owner", format!("removing `{:?}` from `{}`",
                                                         v, name)));
             try!(registry.remove_owners(&name, &v).map_err(|e| {
-                human(format!("failed to remove owners: {}", e))
+                human(format!("failed to remove owners from crate {}: {}", name, e))
             }));
         }
         None => {}
@@ -301,7 +301,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
 
     if opts.list {
         let owners = try!(registry.list_owners(&name).map_err(|e| {
-            human(format!("failed to list owners: {}", e))
+            human(format!("failed to list owners of crate {}: {}", name, e))
         }));
         for owner in owners.iter() {
             print!("{}", owner.login);
index 6b6836ff67059ded12c80374b3fe0e496406bbfe..ea19883be6b0e90db483deb1cce4c260282a780f 100644 (file)
@@ -36,6 +36,7 @@ pub enum Error {
     Unauthorized,
     TokenMissing,
     Io(io::Error),
+    NotFound,
 }
 
 #[derive(RustcDecodable)]
@@ -231,6 +232,7 @@ fn handle(response: result::Result<http::Response, curl::ErrCode>)
         0 => {} // file upload url sometimes
         200 => {}
         403 => return Err(Error::Unauthorized),
+        404 => return Err(Error::NotFound),
         _ => return Err(Error::NotOkResponse(response))
     }
 
@@ -263,6 +265,7 @@ impl fmt::Display for Error {
             Error::Unauthorized => write!(f, "unauthorized API access"),
             Error::TokenMissing => write!(f, "no upload token found, please run `cargo login`"),
             Error::Io(ref e) => write!(f, "io error: {}", e),
+            Error::NotFound => write!(f, "cannot find crate"),
         }
     }
 }