Skip to content
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

Fix --message-format JSON when rustc emits non-JSON warnings #3410

Merged
merged 2 commits into from
Dec 19, 2016

Conversation

fmdkdd
Copy link
Contributor

@fmdkdd fmdkdd commented Dec 15, 2016

The --message-format JSON flag parses all the stderr output of rustc to JSON,
but rustc can emit non-JSON lines to stderr (e.g., for warning about the
unstable -Z flag on the stable channel), causing cargo to fail reporting
compilation errors when using --message-format JSON.

This commit adds a check to look for lines beginning with { to only parse
these lines as JSON. Other lines from rustc are forwarded to the stderr of
cargo.

Fixes #3390.

The `--message-format JSON` flag parses all the stderr output of rustc to JSON,
but rustc can emit non-JSON lines to stderr (e.g., for warning about the
unstable `-Z` flag on the stable channel), causing cargo to fail reporting
compilation errors when using `--message-format JSON`.

This commit adds a check to look for lines beginning with `{` to only parse
these lines as JSON.  Other lines from rustc are forwarded to the stderr of
cargo.

Fixes rust-lang#3390.
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@fmdkdd
Copy link
Contributor Author

fmdkdd commented Dec 15, 2016

@matklad To forward the output to stderr, using cx.config.shell().err() as you suggested caused a bunch of errors of this sort:

260 |     return Ok(Work::new(move |state| {
    |               ^^^^^^^^^ trait `std::cell::RefCell<core::shell::MultiShell>: std::marker::Sync` not satisfied
    |
    = note: `std::cell::RefCell<core::shell::MultiShell>` cannot be shared between threads safely
    = note: required because it appears within the type `util::config::Config`
   [...]

I used io::stderr() directly, which works (errors from rustc are correctly forwarded). But I'm not sure if it's the right solution for that one.

Please let me know if I should change it (and hint at the correct way to do it, since I haven't looked much at dealing with threads in Rust).

@alexcrichton
Copy link
Member

This looks good to me, thanks! Could you also add a test for this?

@fmdkdd
Copy link
Contributor Author

fmdkdd commented Dec 16, 2016

@alexcrichton Done. I've added to make sure that JSON errors are emitted, and that stderr is forwarded.

The test is skipped with a nightly rustc, since the warning for -Z won't appear there, and I didn't know how to trigger a warning for all versions.

@fmdkdd fmdkdd force-pushed the fix-3390-message-format-parse-stderr branch from 397ac0d to 3e32503 Compare December 16, 2016 13:46
@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Collaborator

bors commented Dec 16, 2016

📌 Commit 3e32503 has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Dec 16, 2016

⌛ Testing commit 3e32503 with merge c07ecb0...

bors added a commit that referenced this pull request Dec 16, 2016
…alexcrichton

Fix `--message-format JSON` when rustc emits non-JSON warnings

The `--message-format JSON` flag parses all the stderr output of rustc to JSON,
but rustc can emit non-JSON lines to stderr (e.g., for warning about the
unstable `-Z` flag on the stable channel), causing cargo to fail reporting
compilation errors when using `--message-format JSON`.

This commit adds a check to look for lines beginning with `{` to only parse
these lines as JSON.  Other lines from rustc are forwarded to the stderr of
cargo.

Fixes #3390.
@bors
Copy link
Collaborator

bors commented Dec 16, 2016

💔 Test failed - status-appveyor

@alexcrichton
Copy link
Member

Oh that looks like rust-lang/rust#38177 which was fixed in rust-lang/rust#38357 which should be in the next nightly, I'll r+ then.

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Dec 19, 2016

⌛ Testing commit 3e32503 with merge 109d9c5...

bors added a commit that referenced this pull request Dec 19, 2016
…alexcrichton

Fix `--message-format JSON` when rustc emits non-JSON warnings

The `--message-format JSON` flag parses all the stderr output of rustc to JSON,
but rustc can emit non-JSON lines to stderr (e.g., for warning about the
unstable `-Z` flag on the stable channel), causing cargo to fail reporting
compilation errors when using `--message-format JSON`.

This commit adds a check to look for lines beginning with `{` to only parse
these lines as JSON.  Other lines from rustc are forwarded to the stderr of
cargo.

Fixes #3390.
@bors
Copy link
Collaborator

bors commented Dec 19, 2016

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 109d9c5 to master...

@bors bors merged commit 3e32503 into rust-lang:master Dec 19, 2016
@fmdkdd fmdkdd deleted the fix-3390-message-format-parse-stderr branch December 20, 2016 10:30
@ehuss ehuss added this to the 1.15.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo rustc --message-format=json fails to parse stderr of rustc
6 participants