From c30151b173f7a385bac160a7c6bf756591debddd Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Thu, 21 Sep 2023 15:22:10 -0400 Subject: [PATCH] refactor(TomlManifest): fail when package_root is not a directory Currently, if you're trying to use `TomlManifest::to_real_manifest`, and you pass in something incorrect as the `package_root`, such as the path to the package's manifest, you will get a weird error that looks like this: ``` can't find library `dummy_lib`, rename file to `src/lib.rs` or specify lib.path ``` This is not very helpful, so this change makes us check that `package_root` is a directory, and reports an error early on if it isn't. --- src/cargo/util/toml/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 787286eee28..2e730b4e9fc 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1837,6 +1837,13 @@ impl TomlManifest { } } + if !package_root.is_dir() { + bail!( + "package root '{}' is not a directory", + package_root.display() + ); + }; + let mut nested_paths = vec![]; let mut warnings = vec![]; let mut errors = vec![];