diff --git a/src/manifest.rs b/src/manifest.rs index 2cc3919..81d464f 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -68,6 +68,12 @@ struct Repository { fn read_cargo_toml(path: &Path) -> Result { 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)?; diff --git a/tests/all/build.rs b/tests/all/build.rs index ea66d3b..ea821b5 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -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`")); }