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);
info!(&log, "Packing up the npm package...");
match npm::npm_pack(&crate_path) {
Ok(r) => Ok(r),
Err(Error::Io { .. }) => Err(Error::DirNotFound {
message: "Unable to find the pkg directory".to_owned(),
}),
Err(e) => Err(e),
}?;
npm::npm_pack(&crate_path).map_err(|e| {
match e {
Error::Io { .. } => Error::PkgNotFound {
message: format!("Unable to find the pkg directory at path '{}', set the path as the parent directory of the pkg directory", &crate_path),
},
e => e,
}
})?;
#[cfg(not(target_os = "windows"))]
info!(&log, "Your package is located at {}/pkg", &crate_path);
#[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, "npm info located in the npm debug log");
match npm::npm_publish(&crate_path) {
Ok(r) => Ok(r),
Err(Error::Io { .. }) => Err(Error::DirNotFound {
message: "Unable to find the pkg directory".to_owned(),
}),
Err(e) => Err(e),
}?;
npm::npm_publish(&crate_path).map_err(|e| {
match e {
Error::Io { .. } => Error::PkgNotFound {
message: format!("Unable to find the pkg directory at path '{}', set the path as the parent directory of the pkg directory", &crate_path),
},
e => e,
}
})?;
info!(&log, "Published your package!");
PBAR.message("💥 published your package!");

@ -18,7 +18,7 @@ pub enum Error {
#[fail(display = "{}", message)]
CrateConfig { message: String },
#[fail(display = "{}", message)]
DirNotFound { message: String },
PkgNotFound { message: String },
}
impl Error {
@ -47,7 +47,9 @@ impl Error {
Error::CrateConfig { message: _ } => {
"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()
}
}

Loading…
Cancel
Save