fix(cli): Show the bad manifest path (#15896)

### What does this PR try to resolve?

In most cases, this will just be what you passed on the command line.
Even when its not, that likely represents a programmer error.

I mostly did this to help see what was the cause of a test failure.

### How to test and review this PR?
This commit is contained in:
Weihang Lo 2025-08-29 21:42:27 +00:00 committed by GitHub
commit 51d077c582
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 11 deletions

View File

@ -1075,7 +1075,10 @@ pub fn root_manifest(manifest_path: Option<&Path>, gctx: &GlobalContext) -> Carg
// but in this particular case we need it to fix #3586.
let path = paths::normalize_path(&path);
if !path.ends_with("Cargo.toml") && !crate::util::toml::is_embedded(&path) {
anyhow::bail!("the manifest-path must be a path to a Cargo.toml file")
anyhow::bail!(
"the manifest-path must be a path to a Cargo.toml file: `{}`",
path.display()
)
}
if !path.exists() {
anyhow::bail!("manifest path `{}` does not exist", manifest_path.display())

View File

@ -15,7 +15,9 @@ fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
.arg(manifest_path_argument)
.cwd(p.root().parent().unwrap())
.with_status(101)
.with_stderr_data("[ERROR] the manifest-path must be a path to a Cargo.toml file\n")
.with_stderr_data(
"[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/[..]`\n",
)
.run();
}
@ -333,7 +335,7 @@ fn verify_project_dir_containing_cargo_toml() {
str![[r#"
[
{
"invalid": "the manifest-path must be a path to a Cargo.toml file"
"invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`"
}
]
"#]]
@ -357,7 +359,7 @@ fn verify_project_dir_plus_file() {
str![[r#"
[
{
"invalid": "the manifest-path must be a path to a Cargo.toml file"
"invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar`"
}
]
"#]]
@ -381,7 +383,7 @@ fn verify_project_dir_plus_path() {
str![[r#"
[
{
"invalid": "the manifest-path must be a path to a Cargo.toml file"
"invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz`"
}
]
"#]]

View File

@ -2397,7 +2397,7 @@ fn cargo_metadata_no_deps_path_to_cargo_toml_parent_relative() {
.cwd(p.root().parent().unwrap())
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the manifest-path must be a path to a Cargo.toml file
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
"#]])
.run();
@ -2415,7 +2415,7 @@ fn cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute() {
.cwd(p.root().parent().unwrap())
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the manifest-path must be a path to a Cargo.toml file
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
"#]])
.run();

View File

@ -75,7 +75,7 @@ fn cargo_read_manifest_path_to_cargo_toml_parent_relative() {
.cwd(p.root().parent().unwrap())
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the manifest-path must be a path to a Cargo.toml file
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
"#]])
.run();
@ -93,7 +93,7 @@ fn cargo_read_manifest_path_to_cargo_toml_parent_absolute() {
.cwd(p.root().parent().unwrap())
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the manifest-path must be a path to a Cargo.toml file
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
"#]])
.run();

View File

@ -1358,7 +1358,7 @@ fn cmd_check_with_missing_script_rs() {
.with_status(101)
.with_stdout_data("")
.with_stderr_data(str![[r#"
[ERROR] the manifest-path must be a path to a Cargo.toml file
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/script.rs`
"#]])
.run();
@ -1373,7 +1373,7 @@ fn cmd_check_with_missing_script() {
.with_status(101)
.with_stdout_data("")
.with_stderr_data(str![[r#"
[ERROR] the manifest-path must be a path to a Cargo.toml file
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/script`
"#]])
.run();