json emit mode produces invalid json in terminal if rustfmt errs #3952
Labels
bug
Panic, non-idempotency, invalid code, etc.
only-with-option
requires a non-default option value to reproduce
Whenever rustfmt encounters a condition that results in an
eprint/eprintln
invocation while formatting multiple files, when using the json emit mode the output in the terminal can be invalid json due to the error text splitting apart the json object.Technically stdout will contain the valid json result, and stderr the warnings and errors. However, I believe the emitter can be tweaked so that the full/valid json representation of the formatting results can be displayed to users in the terminal without being broken and invalidated.
This is very similar to #1635, but opening as a separate issue for tracking/visbility and because I believe I have a solution for this problem that is emitter-specific.
To reproduce, use any input file that will err on formatting and that also includes a mod defined in another file. For example:
src/lib.rs
src/bar.rs
with rustfmt.toml:
Then run
cargo fmt
orrustfmt
in recursive/non-skip_children
mode:and then notice the error displayed with the json object for the two respective files that makes the larger json output invalid
error[internal]: line formatted, but exceeded maximum width (maximum: 100 (see
max_widthoption), found: 253)
The text was updated successfully, but these errors were encountered: