Skip to content

Commit

Permalink
Add ToolchainComponentsMissing error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Apr 13, 2021
1 parent 84974df commit 562f18c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 6 deletions.
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 @@ -299,6 +299,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 @@ -491,6 +495,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

0 comments on commit 562f18c

Please sign in to comment.