Skip to content

Commit 71c830c

Browse files
committed
fix: correct error count for cargo check --message-format json
1 parent 01e1ab5 commit 71c830c

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,10 +1867,19 @@ fn on_stderr_line_inner(
18671867

18681868
#[derive(serde::Deserialize)]
18691869
struct CompilerMessage {
1870+
message: String,
18701871
level: String,
18711872
}
1872-
if let Ok(message) = serde_json::from_str::<CompilerMessage>(compiler_message.get()) {
1873-
count_diagnostic(&message.level, options);
1873+
1874+
if let Ok(msg) = serde_json::from_str::<CompilerMessage>(compiler_message.get()) {
1875+
if msg.message.starts_with("aborting due to")
1876+
|| msg.message.ends_with("warning emitted")
1877+
|| msg.message.ends_with("warnings emitted")
1878+
{
1879+
// Skip this line; we'll print our own summary at the end.
1880+
return Ok(true);
1881+
}
1882+
count_diagnostic(&msg.level, options);
18741883
}
18751884

18761885
let msg = machine_message::FromCompiler {

tests/testsuite/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn cargo_fail_with_no_stderr() {
9595
.with_status(101)
9696
.with_stderr_data(str![[r#"
9797
[COMPILING] foo v0.5.0 ([ROOT]/foo)
98-
[ERROR] could not compile `foo` (bin "foo") due to 2 previous errors
98+
[ERROR] could not compile `foo` (bin "foo") due to 1 previous error
9999
100100
"#]])
101101
.run();

tests/testsuite/pkgid.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,6 @@ fn pkgid_json_message_metadata_consistency() {
327327
"reason": "compiler-message",
328328
"...": "{...}"
329329
},
330-
{
331-
"manifest_path": "[ROOT]/foo/Cargo.toml",
332-
"package_id": "path+[ROOTURL]/foo#0.5.0",
333-
"reason": "compiler-message",
334-
"...": "{...}"
335-
},
336330
{
337331
"manifest_path": "[ROOT]/foo/Cargo.toml",
338332
"package_id": "path+[ROOTURL]/foo#0.5.0",

0 commit comments

Comments
 (0)