Skip to content
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

Add ToolchainComponentsMissing error msg #2709

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,7 @@ fn update_from_dist_<'a>(
break Err(e);
}

if let ErrorKind::RequestedComponentsUnavailable(components, manifest, ..) =
e.kind()
{
if let ErrorKind::ToolchainComponentsMissing(components, manifest, ..) = e.kind() {
(download.notify_handler)(Notification::SkippingNightlyMissingComponent(
&toolchain,
current_manifest.as_ref().unwrap_or(manifest),
Expand Down Expand Up @@ -777,9 +775,28 @@ fn try_update_from_dist_<'a>(
&download.notify_handler,
&toolchain.manifest_name(),
true,
)? {
UpdateStatus::Unchanged => Ok(None),
UpdateStatus::Changed => Ok(Some(hash)),
) {
Ok(status) => match status {
UpdateStatus::Unchanged => Ok(None),
UpdateStatus::Changed => Ok(Some(hash)),
},
Err(err) => {
return if let ErrorKind::RequestedComponentsUnavailable(
cs,
manifest,
toolchain_str,
) = err.kind()
{
Err(ErrorKind::ToolchainComponentsMissing(
cs.to_owned(),
manifest.to_owned(),
toolchain_str.to_owned(),
)
.into())
} else {
Err(err)
}
}
};
}
Ok(None) => return Ok(None),
Expand Down
52 changes: 52 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ error_chain! {
description("some requested components are unavailable to download")
display("{}", component_unavailable_msg(&c, &manifest, &toolchain))
}
ToolchainComponentsMissing(c: Vec<Component>, manifest: Manifest,toolchain: String) {
description("at least one of the requested components is unavailable to download")
display("{}", components_missing_msg(&c,&manifest, &toolchain))
}
UnknownMetadataVersion(v: String) {
description("unknown metadata version")
display("unknown metadata version: '{}'", v)
Expand Down Expand Up @@ -495,6 +499,54 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
String::from_utf8(buf).unwrap()
}

fn components_missing_msg(cs: &[Component], manifest: &Manifest, toolchain: &str) -> String {
assert!(!cs.is_empty());
let mut buf = vec![];
let suggestion = format!(" rustup toolchain add {} --profile minimal", toolchain);
let nightly_tips = "Sometimes not all components are available in any given nightly. ";

if cs.len() == 1 {
let _ = writeln!(
buf,
"component {} is unavailable for download for channel '{}'",
&cs[0].description(manifest),
toolchain,
);

if toolchain.starts_with("nightly") {
let _ = write!(buf, "{}", nightly_tips.to_string());
}

let _ = write!(
buf,
"If you don't need the component, you could try a minimal installation with:\n\n{}",
suggestion
);
} else {
let cs_str = cs
.iter()
.map(|c| c.description(manifest))
.collect::<Vec<_>>()
.join(", ");
let _ = write!(
buf,
"some components unavailable for download for channel '{}': {}",
toolchain, cs_str
);

if toolchain.starts_with("nightly") {
let _ = write!(buf, "{}", nightly_tips.to_string());
}
let _ = write!(
buf,
"If you don't need the components, you could try a minimal installation with:\n\n{}",
suggestion
);
}

String::from_utf8(buf).unwrap()
}

fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
if Toolchain::is_custom_name(toolchain) {
return "\nnote: this is a custom toolchain, which cannot use `rustup component add`\n\
Expand Down
17 changes: 17 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,23 @@ fn update_unavailable_std() {
});
}

#[test]
fn add_missing_component_toolchain() {
setup(&|config| {
make_component_unavailable(config, "rust-std", &this_host_triple());
expect_err(
config,
&["rustup", "toolchain", "add", "nightly"],
for_host!(
r"component 'rust-std' for target '{0}' is unavailable for download for channel 'nightly'
Sometimes not all components are available in any given nightly. If you don't need the component, you could try a minimal installation with:

rustup toolchain add nightly --profile minimal"
),
);
});
}

#[test]
fn update_unavailable_force() {
setup(&|config| {
Expand Down