From 840c7bd03c3491c0fe0479b744c216079c855038 Mon Sep 17 00:00:00 2001 From: Mackiovello Date: Wed, 4 Jul 2018 19:59:37 +0200 Subject: [PATCH] Return custom error if pkg directory is not found --- src/command/pack.rs | 10 +++++++++- src/error.rs | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/command/pack.rs b/src/command/pack.rs index be0f45a..a945819 100644 --- a/src/command/pack.rs +++ b/src/command/pack.rs @@ -9,7 +9,15 @@ pub fn pack(path: Option, 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")] diff --git a/src/error.rs b/src/error.rs index 0bd2ba6..e2e937e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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() } }