Return custom error if pkg directory is not found

master
Mackiovello 7 years ago
parent b0470b08e0
commit 840c7bd03c
  1. 10
      src/command/pack.rs
  2. 3
      src/error.rs

@ -9,7 +9,15 @@ pub fn pack(path: Option<String>, log: &Logger) -> result::Result<(), Error> {
let crate_path = set_crate_path(path);
info!(&log, "Packing up the npm package...");
npm::npm_pack(&crate_path)?;
match npm::npm_pack(&crate_path) {
Ok(r) => r,
Err(Error::Io { .. }) => {
return Err(Error::DirNotFound {
message: "Unable to find the pkg directory".to_owned(),
});
}
Err(e) => return Err(e),
};
#[cfg(not(target_os = "windows"))]
info!(&log, "Your package is located at {}/pkg", &crate_path);
#[cfg(target_os = "windows")]

@ -17,6 +17,8 @@ pub enum Error {
Cli { message: String, stderr: String },
#[fail(display = "{}", message)]
CrateConfig { message: String },
#[fail(display = "{}", message)]
DirNotFound { message: String },
}
impl Error {
@ -45,6 +47,7 @@ impl Error {
Error::CrateConfig { message: _ } => {
"There was a crate configuration error. Details:\n\n"
}
Error::DirNotFound { message: _ } => "Unable to find the directory\n\n",
}.to_string()
}
}

Loading…
Cancel
Save