-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
--message-format=json
doesn't emit every error message
#5992
Comments
It looks like |
@ehuss hm I'm not quite following how the recursion depth and |
It's a little confusing because there are two recursion errors. There's the recursion error that happens inside rustc during macro expansion which is the error we're trying to report. However, rustc includes a giant JSON structure with all the expansions nested to the point where it failed. When the JSON is parsed by cargo (here), it fails with a RecursionLimitExceeded error from serde_json. serde_json's limit is hardcoded to 128 here. When the json parsing fails, the error gets dropped here if the process also fails. The few solutions I've thought of aren't very good. We could change serde_json to allow us to set the recursion limit, but to what value? See also serde-rs/json#162. rustc can emit arbitrarily deep structures (unless the stack overflows). Cargo could emit a warning with the json string when it fails to parse the JSON, so you can at least see that something went wrong. |
Ah ok, thanks for the explanation, that definitely makes sense! I wonder if we could perhaps tack on more error information to the process failure as well, to be emitted as warnings maybe? Emitting a warning otherwise sounds fine by me |
I made a JSON library that does not use any recursion. Maybe that would be useful here? |
@dtolnay I saw your announcement on reddit and immediately thought of this issue. |
Just for the record here, there was an attempt in #6032 switching to a library called miniserde, but that change wasn't accepted because it introduced a second json parser and serialization implementation. |
Fix missing messages when --message-format=json is deeply nested This commit switches from `serde_json::Value` to [`RawValue`](https://docs.rs/serde_json/1.0/serde_json/value/struct.RawValue.html), which can process arbitrarily deeply nested JSON content without recursion. Fixes #5992. @ehuss
Show error on JSON parse error and nonzero exit. If JSON parsing failed, and rustc exits nonzero, the error was lost. This would have made it easier to diagnose #5992.
For future references, |
Steps to reproduce:
Replace
src/main.rs
with this:Then if you build it:
you'll get the following error:
however if you build it with:
then the error message is missing from the output. I'd expect
cargo
to emit a line with{"reason": "compiler-message", ...}
just as it usually does for errors; instead it emits no"compiler-message"
s, e.g. the output of this (to match only"compiler-message"
s):is empty.
The text was updated successfully, but these errors were encountered: