From db6891f2446260c62c62b9c5a43d0a01f017324f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 29 Aug 2025 15:42:44 -0500 Subject: [PATCH] fix(cli): Show the bad manifest path 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. --- src/cargo/util/command_prelude.rs | 5 ++++- tests/testsuite/bad_manifest_path.rs | 10 ++++++---- tests/testsuite/metadata.rs | 4 ++-- tests/testsuite/read_manifest.rs | 4 ++-- tests/testsuite/script.rs | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index e1d2f9a88..b1e145239 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -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()) diff --git a/tests/testsuite/bad_manifest_path.rs b/tests/testsuite/bad_manifest_path.rs index e5cd8ea50..c497e303f 100644 --- a/tests/testsuite/bad_manifest_path.rs +++ b/tests/testsuite/bad_manifest_path.rs @@ -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`" } ] "#]] diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 0f078a4e0..a150add9e 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -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(); diff --git a/tests/testsuite/read_manifest.rs b/tests/testsuite/read_manifest.rs index 30b2d455a..496088874 100644 --- a/tests/testsuite/read_manifest.rs +++ b/tests/testsuite/read_manifest.rs @@ -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(); diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index 175570733..a7f23cfc2 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -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();