-
Notifications
You must be signed in to change notification settings - Fork 965
feat: improve error message for rustup which
#4429
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
base: master
Are you sure you want to change the base?
feat: improve error message for rustup which
#4429
Conversation
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.
Seems like a good start!
Obviously this should pass CI -- would also be great if you could make sure there are tests to cover the new code paths.
src/cli/rustup_mode.rs
Outdated
let toolchain_name = toolchain.name(); | ||
let Some(component_name) = component_for_bin(binary) else { | ||
return Err(anyhow!( | ||
"Unknown binary '{binary}' in toolchain '{toolchain_name}'.", |
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.
Nit: should drop the capital at the start and period at the end here for consistency.
src/cli/rustup_mode.rs
Outdated
return Err(anyhow!( | ||
"'{binary}' is not installed for the toolchain '{toolchain_name}'.\nTo install, run `rustup component add {selector}{component_name}`" | ||
)); |
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.
Nit: idiomatically, no need to use return
here, can just make Err(..)
the tail expression.
src/cli/rustup_mode.rs
Outdated
let active = matches!(cfg.active_toolchain(), Ok(Some((t, _))) if &t == toolchain_name); | ||
let selector = if active { | ||
String::new() | ||
} else { | ||
format!("--toolchain {} ", toolchain.name()) | ||
}; |
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.
This seems little roundabout, what about something more like:
let selector = match cfg.active_toolchain() {
Ok(Some((t, _))) if t == toolchain_name => String::new(),
_ => format!("--toolchain {} ", toolchain.name()),
};
src/cli/rustup_mode.rs
Outdated
@@ -47,6 +46,7 @@ use crate::{ | |||
}, | |||
utils::{self, ExitCode}, | |||
}; | |||
use crate::{component_for_bin, dist::AutoInstallMode}; |
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.
If you're going to move this around, would be nicer to move both of these into the big crate
block just above. 👍
fbfb71c
to
aa79802
Compare
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.
LGTM! Would be good to squash your commits into a single one, and mark the PR as ready for review.
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.
The situation with this PR merged seems strictly better to me than the current state on master. Maybe there are still further improvements to be made but it's not obvious to me they should necessarily be a part of this PR. |
@djc I agree. That said, it might still be worth it if @Bogay can put these considerations at the top of this thread (in a separate section, say |
54ef67d
to
02c0813
Compare
I have put these considerations to the PR description and squash my commits into one. I think it's ready for review now. Regarding the edge case I mentioned, I am not sure whether I should try to solve it? or wait for someone to encounter it and open an issue. |
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.
LGTM, and thanks for the patch!
@djc Can you confirm that your concerns have been properly addressed as well?
@Bogay If you think a further PR is possible, I would greatly appreciate it :) |
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.
I've updated the relevant error message to suggest how users can install the missing component. For the long term, I'm thinking we should find a more consistent way to manage error messages across the project. Do you have any thoughts on how we could approach this, perhaps with custom error types or utility functions?
src/cli/rustup_mode.rs
Outdated
"To install, try `rustup component add --toolchain {} rust-docs`", | ||
"run `rustup component add --toolchain {} rust-docs` to install it", |
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.
Because info!
add info:
prefix to output message and I think info: help:
looks a little weird. I don't add the help:
prefix here. Not sure whether it's better to merge these two lines info the error message below?
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.
Nice catch! Yeah, I think in that case it'd be better to just do a single info!()
call instead of two...
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.
Updated. We have only one info!()
call now 👍
Also adds more tests for `rustup which`. Includes: - ask binary included by uninstalled component - ask binary included by uninstalled component with non-default toolchain - ask binary not known to be included by what toolchain
to suggest command to install missing components. make them more consistent.
1248e0e
to
0bcf123
Compare
Close #3321
This PR improves the error message for
rustup which
by providing a suggested command to install the missing component, provided that we know which one it is.Limitations
Some edge cases are not coverd, e.g. if a binary is expected to be provided by a component but not found on disk. (which is handled in
DistributableToolchain::recursion_error
)