Skip to content

Commit db6891f

Browse files
committed
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.
1 parent a6c58d4 commit db6891f

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/cargo/util/command_prelude.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,10 @@ pub fn root_manifest(manifest_path: Option<&Path>, gctx: &GlobalContext) -> Carg
10751075
// but in this particular case we need it to fix #3586.
10761076
let path = paths::normalize_path(&path);
10771077
if !path.ends_with("Cargo.toml") && !crate::util::toml::is_embedded(&path) {
1078-
anyhow::bail!("the manifest-path must be a path to a Cargo.toml file")
1078+
anyhow::bail!(
1079+
"the manifest-path must be a path to a Cargo.toml file: `{}`",
1080+
path.display()
1081+
)
10791082
}
10801083
if !path.exists() {
10811084
anyhow::bail!("manifest path `{}` does not exist", manifest_path.display())

tests/testsuite/bad_manifest_path.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
1515
.arg(manifest_path_argument)
1616
.cwd(p.root().parent().unwrap())
1717
.with_status(101)
18-
.with_stderr_data("[ERROR] the manifest-path must be a path to a Cargo.toml file\n")
18+
.with_stderr_data(
19+
"[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/[..]`\n",
20+
)
1921
.run();
2022
}
2123

@@ -333,7 +335,7 @@ fn verify_project_dir_containing_cargo_toml() {
333335
str![[r#"
334336
[
335337
{
336-
"invalid": "the manifest-path must be a path to a Cargo.toml file"
338+
"invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`"
337339
}
338340
]
339341
"#]]
@@ -357,7 +359,7 @@ fn verify_project_dir_plus_file() {
357359
str![[r#"
358360
[
359361
{
360-
"invalid": "the manifest-path must be a path to a Cargo.toml file"
362+
"invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar`"
361363
}
362364
]
363365
"#]]
@@ -381,7 +383,7 @@ fn verify_project_dir_plus_path() {
381383
str![[r#"
382384
[
383385
{
384-
"invalid": "the manifest-path must be a path to a Cargo.toml file"
386+
"invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz`"
385387
}
386388
]
387389
"#]]

tests/testsuite/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@ fn cargo_metadata_no_deps_path_to_cargo_toml_parent_relative() {
23972397
.cwd(p.root().parent().unwrap())
23982398
.with_status(101)
23992399
.with_stderr_data(str![[r#"
2400-
[ERROR] the manifest-path must be a path to a Cargo.toml file
2400+
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
24012401
24022402
"#]])
24032403
.run();
@@ -2415,7 +2415,7 @@ fn cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute() {
24152415
.cwd(p.root().parent().unwrap())
24162416
.with_status(101)
24172417
.with_stderr_data(str![[r#"
2418-
[ERROR] the manifest-path must be a path to a Cargo.toml file
2418+
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
24192419
24202420
"#]])
24212421
.run();

tests/testsuite/read_manifest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn cargo_read_manifest_path_to_cargo_toml_parent_relative() {
7575
.cwd(p.root().parent().unwrap())
7676
.with_status(101)
7777
.with_stderr_data(str![[r#"
78-
[ERROR] the manifest-path must be a path to a Cargo.toml file
78+
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
7979
8080
"#]])
8181
.run();
@@ -93,7 +93,7 @@ fn cargo_read_manifest_path_to_cargo_toml_parent_absolute() {
9393
.cwd(p.root().parent().unwrap())
9494
.with_status(101)
9595
.with_stderr_data(str![[r#"
96-
[ERROR] the manifest-path must be a path to a Cargo.toml file
96+
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`
9797
9898
"#]])
9999
.run();

tests/testsuite/script.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ fn cmd_check_with_missing_script_rs() {
13581358
.with_status(101)
13591359
.with_stdout_data("")
13601360
.with_stderr_data(str![[r#"
1361-
[ERROR] the manifest-path must be a path to a Cargo.toml file
1361+
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/script.rs`
13621362
13631363
"#]])
13641364
.run();
@@ -1373,7 +1373,7 @@ fn cmd_check_with_missing_script() {
13731373
.with_status(101)
13741374
.with_stdout_data("")
13751375
.with_stderr_data(str![[r#"
1376-
[ERROR] the manifest-path must be a path to a Cargo.toml file
1376+
[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/script`
13771377
13781378
"#]])
13791379
.run();

0 commit comments

Comments
 (0)