Skip to content

Commit 764b5d9

Browse files
committed
Add ToolchainComponentsMissing error msg
1 parent 4cdedeb commit 764b5d9

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

src/dist/dist.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,7 @@ fn update_from_dist_<'a>(
625625
break Err(e);
626626
}
627627

628-
if let ErrorKind::RequestedComponentsUnavailable(components, manifest, ..) =
629-
e.kind()
630-
{
628+
if let ErrorKind::ToolchainComponentsMissing(components, manifest, ..) = e.kind() {
631629
(download.notify_handler)(Notification::SkippingNightlyMissingComponent(
632630
&toolchain,
633631
current_manifest.as_ref().unwrap_or(manifest),
@@ -777,9 +775,28 @@ fn try_update_from_dist_<'a>(
777775
&download.notify_handler,
778776
&toolchain.manifest_name(),
779777
true,
780-
)? {
781-
UpdateStatus::Unchanged => Ok(None),
782-
UpdateStatus::Changed => Ok(Some(hash)),
778+
) {
779+
Ok(status) => match status {
780+
UpdateStatus::Unchanged => Ok(None),
781+
UpdateStatus::Changed => Ok(Some(hash)),
782+
},
783+
Err(err) => {
784+
return if let ErrorKind::RequestedComponentsUnavailable(
785+
cs,
786+
manifest,
787+
toolchain_str,
788+
) = err.kind()
789+
{
790+
Err(ErrorKind::ToolchainComponentsMissing(
791+
cs.to_owned(),
792+
manifest.to_owned(),
793+
toolchain_str.to_owned(),
794+
)
795+
.into())
796+
} else {
797+
Err(err)
798+
}
799+
}
783800
};
784801
}
785802
Ok(None) => return Ok(None),

src/errors.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ error_chain! {
303303
description("some requested components are unavailable to download")
304304
display("{}", component_unavailable_msg(&c, &manifest, &toolchain))
305305
}
306+
ToolchainComponentsMissing(c: Vec<Component>, manifest: Manifest,toolchain: String) {
307+
description("at least one of the requested components is unavailable to download")
308+
display("{}", components_missing_msg(&c,&manifest, &toolchain))
309+
}
306310
UnknownMetadataVersion(v: String) {
307311
description("unknown metadata version")
308312
display("unknown metadata version: '{}'", v)
@@ -495,6 +499,54 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
495499
String::from_utf8(buf).unwrap()
496500
}
497501

502+
fn components_missing_msg(cs: &[Component], manifest: &Manifest, toolchain: &str) -> String {
503+
assert!(!cs.is_empty());
504+
let mut buf = vec![];
505+
let suggestion = format!(" rustup toolchain add {} --profile minimal", toolchain);
506+
let nightly_tips = "Sometimes not all components are available in any given nightly. ";
507+
508+
if cs.len() == 1 {
509+
let _ = writeln!(
510+
buf,
511+
"component {} is unavailable for download for channel '{}'",
512+
&cs[0].description(manifest),
513+
toolchain,
514+
);
515+
516+
if toolchain.starts_with("nightly") {
517+
let _ = write!(buf, "{}", nightly_tips.to_string());
518+
}
519+
520+
let _ = write!(
521+
buf,
522+
"If you don't need the component, you could try a minimal installation with:\n\n{}",
523+
suggestion
524+
);
525+
} else {
526+
let cs_str = cs
527+
.iter()
528+
.map(|c| c.description(manifest))
529+
.collect::<Vec<_>>()
530+
.join(", ");
531+
let _ = write!(
532+
buf,
533+
"some components unavailable for download for channel '{}': {}",
534+
toolchain, cs_str
535+
);
536+
537+
if toolchain.starts_with("nightly") {
538+
let _ = write!(buf, "{}", nightly_tips.to_string());
539+
}
540+
let _ = write!(
541+
buf,
542+
"If you don't need the components, you could try a minimal installation with:\n\n{}",
543+
suggestion
544+
);
545+
}
546+
547+
String::from_utf8(buf).unwrap()
548+
}
549+
498550
fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
499551
if Toolchain::is_custom_name(toolchain) {
500552
return "\nnote: this is a custom toolchain, which cannot use `rustup component add`\n\

tests/cli-v2.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,23 @@ fn update_unavailable_std() {
10851085
});
10861086
}
10871087

1088+
#[test]
1089+
fn add_missing_component_toolchain() {
1090+
setup(&|config| {
1091+
make_component_unavailable(config, "rust-std", &this_host_triple());
1092+
expect_err(
1093+
config,
1094+
&["rustup", "toolchain", "add", "nightly"],
1095+
for_host!(
1096+
r"component 'rust-std' for target '{0}' is unavailable for download for channel 'nightly'
1097+
Sometimes not all components are available in any given nightly. If you don't need the component, you could try a minimal installation with:
1098+
1099+
rustup toolchain add nightly --profile minimal"
1100+
),
1101+
);
1102+
});
1103+
}
1104+
10881105
#[test]
10891106
fn update_unavailable_force() {
10901107
setup(&|config| {

0 commit comments

Comments
 (0)