Skip to content

rustc bad cli arg error messages doesn't respect --error-format=json #140101

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

Open
jieyouxu opened this issue Apr 21, 2025 · 1 comment
Open

rustc bad cli arg error messages doesn't respect --error-format=json #140101

jieyouxu opened this issue Apr 21, 2025 · 1 comment
Labels
A-CLI Area: Command-line interface (CLI) to the compiler A-compiletest Area: The compiletest test runner A-diagnostics Area: Messages for errors, warnings, and lints C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jieyouxu
Copy link
Member

jieyouxu commented Apr 21, 2025

Not surprising (and I don't really consider this a bug necessarily), but something like

$ rustc --error-format=json --emit
error: Argument to option 'emit' missing
       Usage:
           --emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
                               Comma separated list of types of output for the
                               compiler to emit

doesn't respect --error-format=json. I think that is entirely reasonable, since --error-format itself might be missing its value or get passed some invalid value 🤷

Just opening an issue to note this, because the implication for ui tests is that this obviously won't get picked up by compiletest for the //~? error annotations which are based on JSON diagnostic messages.

For test writers, the implication is simply that you can't use

//@ compile-flags: --emit

//~? ERROR: Argument to option 'emit' missing

and you'll need to use

//@ compile-flags: --emit
//@ error-pattern: Argument to option 'emit' missing

as an fallback.

@jieyouxu jieyouxu added A-CLI Area: Command-line interface (CLI) to the compiler A-compiletest Area: The compiletest test runner C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 21, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 21, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 21, 2025
@jieyouxu jieyouxu added the A-diagnostics Area: Messages for errors, warnings, and lints label Apr 21, 2025
@bjorn3
Copy link
Member

bjorn3 commented Apr 21, 2025

This error message is emitted at

early_dcx.early_fatal(msg.unwrap_or_else(|| e.to_string()));
which doesn't have access to the parsed --error-format as parsing arguments failed. I don't think there is an easy solution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: Command-line interface (CLI) to the compiler A-compiletest Area: The compiletest test runner A-diagnostics Area: Messages for errors, warnings, and lints C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants