Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UX for pack and publish path expectations #198

Merged
merged 12 commits into from
Jul 19, 2018
10 changes: 9 additions & 1 deletion src/command/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably just be Ok(r) => (),

Err(Error::Io { .. }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this match is too broad. I only want to catch os error 2: directory not found. I don't want to swallow other IO errors. Investigate how to do that.

return Err(Error::DirNotFound {
message: "Unable to find the pkg directory".to_owned(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be more specific? Should it also print the path that the user entered? Not sure yet.

});
}
Err(e) => return Err(e),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These explicit return statements feel like code smells. Maybe I can use the ? operator here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should try something like this instead:

my_function_call().map_err(|e| match {
  interesting_error => something_else,
  stuff => stuff,
})?

};
#[cfg(not(target_os = "windows"))]
info!(&log, "Your package is located at {}/pkg", &crate_path);
#[cfg(target_os = "windows")]
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
Expand Down