Better error message when running wasm-pack in a non-crate directory

master
Nick Fitzgerald 7 years ago
parent ed35e497c7
commit 7fff2b6a15
  1. 6
      src/manifest.rs
  2. 5
      tests/all/build.rs

@ -68,6 +68,12 @@ struct Repository {
fn read_cargo_toml(path: &Path) -> Result<CargoManifest, Error> {
let manifest_path = path.join("Cargo.toml");
if !manifest_path.is_file() {
return Error::crate_config(&format!(
"Crate directory is missing a `Cargo.toml` file; is `{}` the wrong directory?",
path.display()
)).map(|_| unreachable!());
}
let mut cargo_file = File::open(manifest_path)?;
let mut cargo_contents = String::new();
cargo_file.read_to_string(&mut cargo_contents)?;

@ -11,8 +11,11 @@ fn build_in_non_crate_directory_doesnt_panic() {
&fixture.path.display().to_string(),
]).unwrap();
let logger = logger::new(&cli.cmd, cli.verbosity).unwrap();
let result = command::run_wasm_pack(cli.cmd, &logger);
assert!(
command::run_wasm_pack(cli.cmd, &logger).is_err(),
result.is_err(),
"running wasm-pack in a non-crate directory should fail, but it should not panic"
);
let err_msg = result.unwrap_err().to_string();
assert!(err_msg.contains("missing a `Cargo.toml`"));
}

Loading…
Cancel
Save