Make error more specific

master
Mackiovello 7 years ago
parent ec17b8aa7e
commit 8efabfa3af
  1. 15
      src/command/pack.rs
  2. 15
      src/command/publish.rs
  3. 6
      src/error.rs

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

@ -10,13 +10,14 @@ pub fn publish(path: Option<String>, log: &Logger) -> result::Result<(), Error>
info!(&log, "Publishing the npm package..."); info!(&log, "Publishing the npm package...");
info!(&log, "npm info located in the npm debug log"); info!(&log, "npm info located in the npm debug log");
match npm::npm_publish(&crate_path) { npm::npm_publish(&crate_path).map_err(|e| {
Ok(r) => Ok(r), match e {
Err(Error::Io { .. }) => Err(Error::DirNotFound { Error::Io { .. } => Error::PkgNotFound {
message: "Unable to find the pkg directory".to_owned(), message: format!("Unable to find the pkg directory at path '{}', set the path as the parent directory of the pkg directory", &crate_path),
}), },
Err(e) => Err(e), e => e,
}?; }
})?;
info!(&log, "Published your package!"); info!(&log, "Published your package!");
PBAR.message("💥 published your package!"); PBAR.message("💥 published your package!");

@ -18,7 +18,7 @@ pub enum Error {
#[fail(display = "{}", message)] #[fail(display = "{}", message)]
CrateConfig { message: String }, CrateConfig { message: String },
#[fail(display = "{}", message)] #[fail(display = "{}", message)]
DirNotFound { message: String }, PkgNotFound { message: String },
} }
impl Error { impl Error {
@ -47,7 +47,9 @@ impl Error {
Error::CrateConfig { message: _ } => { Error::CrateConfig { message: _ } => {
"There was a crate configuration error. Details:\n\n" "There was a crate configuration error. Details:\n\n"
} }
Error::DirNotFound { message: _ } => "Unable to find the directory\n\n", Error::PkgNotFound {
message: _,
} => "Unable to find the 'pgk' directory at the path, set the path as the parent of the 'pkg' directory \n\n",
}.to_string() }.to_string()
} }
} }

Loading…
Cancel
Save