-
-
Notifications
You must be signed in to change notification settings - Fork 34
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 some errors not being reported on console #963
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #963 +/- ##
==========================================
+ Coverage 73.46% 75.17% +1.71%
==========================================
Files 80 80
Lines 5548 5564 +16
==========================================
+ Hits 4076 4183 +107
+ Misses 1472 1381 -91 ☔ View full report in Codecov by Sentry. |
Hey, Thanks a lot for the PR! I think I gave you the wrong pointer previously in #934, because once the context is built, it is assumed we have a RustVersion: https://github.com/foresterre/cargo-msrv/blob/main/src/context/verify.rs#L16 Looking in more detail at this PR, I think you're on the right track. An error is produced after all (courtesy of The first step which I feel is a good step in the right direction, is to change the tracing::error! to a There is a small problem though 🥲! This works for human output methods, e.g. running
However, we don't want this kind of output if the
The problem is that I've initialized the https://github.com/foresterre/cargo-msrv/blob/main/src/bin/cargo-msrv.rs#L56 before the reporter. It makes to do so because the context also tells us, which output format ought to be used (i.e. which reporter handler to use) so it's a bit of a chicken and egg problem. |
One way to solve it would be to manually print The property is I made a small proof of concept, similar to yours: fn main() {
let opts = parse_opts(std::env::args_os);
let output_format = opts.shared_opts.user_output_opts.output_format;
std::process::exit(
match _main(opts) {
Ok((_guard, exit_code)) => exit_code,
Err(err) => {
// Can't use tracing::error! here, because it may not have been initialized!
report_init_err(err, output_format);
ExitCode::Failure
}
}
.into(),
);
}
fn report_init_err(err: InstanceError, output_format: OutputFormat) {
match output_format {
OutputFormat::Human => eprintln!("{}", err),
OutputFormat::Minimal => eprintln!("error\n{}", err),
OutputFormat::Json => {
eprintln!(
"{}",
serde_json::json!({
"type": "init",
"failure": format!("{}", err),
})
);
}
OutputFormat::None => {}
}
}
fn parse_opts<I: IntoIterator<Item = OsString>, F: FnOnce() -> I + Clone>(
args: F,
) -> CargoMsrvOpts {
let matches = CargoCli::parse_args(args());
let opts = matches.to_cargo_msrv_cli().to_opts();
opts
} And then
Compared to yours I tried to keep as much intact (but as you can see it's very similar in concept), and did some manual effort to get the right output format. With this concept, if I use the
and
Which ever formatting we choose for the json, please also add it here: https://github.com/foresterre/cargo-msrv/blob/main/book/src/output-formats/json.md#list-of-events I put it all on a branch. You may use whatever you want: 8331209 (https://github.com/foresterre/cargo-msrv/blob/concept/src/bin/cargo-msrv.rs#L19-L68) P.S. If you want to rename the vague |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to address the different output formats. Please see my other comments for details.
- use
eprintln!
overprintln!
- rename _main_1 etc. to more descriptive names
Are you sure that the Because I am calling In my opinion calling |
Thanks for the explanation! That will do it indeed. Then I only have the request to rename the different |
Do you have any suggestions? |
Just some ideas:
or
An alternative could be to let setup_context (_main_3) return the context and call run_app from main. |
Thanks for the feedback and the suggestions! I have adjusted the code now, and force-pushed the changes. Please let me know if I should change anything else. |
Conversion of the output format argument was only happening for `Context` but not for the direct access in `cargo-msrv.rs`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Fixes #934
It seems there were two issues:
CargoMSRVError
toInstanceError
InstanceError
not being shown on console by default, but instead only being logged withtracing::error!
(and usage of
tracing::error!
might also have been problematic because theInstanceError
might be about setup oftracing
having failed)It looks like this can be solved by removing
Context::output_format
(since this information is also available fromopts
), and then performing theContext::try_from
call later and handling errors like normal execution errors.For now I have marked this as draft and added some notes as comments below. Please let me know if I overlooked something, and what you think.