Skip to content

Improve "wrong output" error. #9905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,11 @@ impl BuildOutput {
let (key, value) = match (key, value) {
(Some(a), Some(b)) => (a, b.trim_end()),
// Line started with `cargo:` but didn't match `key=value`.
_ => bail!("Wrong output in {}: `{}`", whence, line),
_ => bail!("invalid output in {}: `{}`\n\
Expected a line with `cargo:key=value` with an `=` character, \
but none was found.\n\
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs.", whence, line),
};

// This will rewrite paths if the target directory has been moved.
Expand Down
28 changes: 28 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4942,3 +4942,31 @@ fn duplicate_script_with_extra_env() {
.run();
}
}

#[cargo_test]
fn wrong_output() {
let p = project()
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
fn main() {
println!("cargo:example");
}
"#,
)
.build();

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo [..]
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo:example`
Expected a line with `cargo:key=value` with an `=` character, but none was found.
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs.
",
)
.run();
}