diff --git a/src/command/pack.rs b/src/command/pack.rs index b2dae6c..cbdffbf 100644 --- a/src/command/pack.rs +++ b/src/command/pack.rs @@ -9,13 +9,14 @@ pub fn pack(path: Option, 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")] diff --git a/src/command/publish.rs b/src/command/publish.rs index 51cfdc7..52eac3c 100644 --- a/src/command/publish.rs +++ b/src/command/publish.rs @@ -10,13 +10,14 @@ pub fn publish(path: Option, 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!"); diff --git a/src/error.rs b/src/error.rs index e2e937e..4fac62c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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() } }