Skip to content

Commit 137685b

Browse files
authored
Merge pull request #2562 from kinnison/fix-failed-install-2547
UX: Report non-installable toolchains
2 parents d3a7f40 + 1c1c03a commit 137685b

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ error_chain! {
295295
description("toolchain is not installed")
296296
display("toolchain '{}' is not installed", t)
297297
}
298+
ToolchainNotInstallable(t: String) {
299+
description("toolchain is not installable")
300+
display("toolchain '{}' is not installable", t)
301+
}
298302
ToolchainNotSelected {
299303
description("toolchain is not selected")
300304
display("no override and no default toolchain set")

src/install.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::dist::dist;
55
use crate::dist::download::DownloadCfg;
66
use crate::dist::prefix::InstallPrefix;
77
use crate::dist::Notification;
8-
use crate::errors::Result;
8+
use crate::errors::{ErrorKind, Result};
99
use crate::notifications::Notification as RootNotification;
1010
use crate::toolchain::{CustomToolchain, DistributableToolchain, Toolchain, UpdateStatus};
1111
use crate::utils::utils;
@@ -76,7 +76,12 @@ impl<'a> InstallMethod<'a> {
7676
(false, _) => UpdateStatus::Unchanged,
7777
};
7878

79-
Ok(status)
79+
// Final check, to ensure we're installed
80+
if !toolchain.exists() {
81+
Err(ErrorKind::ToolchainNotInstallable(toolchain.name().to_string()).into())
82+
} else {
83+
Ok(status)
84+
}
8085
}
8186

8287
pub fn run(self, path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<bool> {

tests/cli-inst-interactive.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use rustup::test::with_saved_path;
1212
use rustup::utils::raw;
1313

1414
use crate::mock::clitools::{
15-
self, expect_ok, expect_stderr_ok, expect_stdout_ok, run, set_current_dist_date, Config,
16-
SanitizedOutput, Scenario,
15+
self, expect_err, expect_ok, expect_stderr_ok, expect_stdout_ok, run, set_current_dist_date,
16+
Config, SanitizedOutput, Scenario,
1717
};
1818

1919
fn run_input(config: &Config, args: &[&str], input: &str) -> SanitizedOutput {
@@ -605,3 +605,21 @@ fn with_no_prompt_install_succeeds_if_rustc_exists() {
605605
assert!(out.ok);
606606
});
607607
}
608+
609+
// Issue 2547
610+
#[test]
611+
fn install_non_installable_toolchain() {
612+
clitools::setup(Scenario::Unavailable, &|config| {
613+
expect_err(
614+
config,
615+
&[
616+
"rustup-init",
617+
"-y",
618+
"--no-modify-path",
619+
"--default-toolchain",
620+
"nightly",
621+
],
622+
"is not installable",
623+
);
624+
})
625+
}

tests/cli-misc.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,26 @@ fn update_unavailable_rustc() {
685685
});
686686
}
687687

688+
// issue 2562
689+
#[test]
690+
fn install_unavailable_platform() {
691+
clitools::setup(Scenario::Unavailable, &|config| {
692+
set_current_dist_date(config, "2015-01-02");
693+
// explicit attempt to install should fail
694+
expect_err(
695+
config,
696+
&["rustup", "toolchain", "install", "nightly"],
697+
"is not installable",
698+
);
699+
// implicit attempt to install should fail
700+
expect_err(
701+
config,
702+
&["rustup", "default", "nightly"],
703+
"is not installable",
704+
);
705+
});
706+
}
707+
688708
#[test]
689709
fn update_nightly_even_with_incompat() {
690710
clitools::setup(Scenario::MissingComponent, &|config| {

tests/cli-v2.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,12 @@ fn bad_sha_on_manifest() {
310310
sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa");
311311
let sha_str = String::from_utf8(sha_bytes).unwrap();
312312
rustup::utils::raw::write_file(&sha_file, &sha_str).unwrap();
313-
expect_ok(config, &["rustup", "default", "nightly"]);
313+
// We fail because the sha is bad, but we should emit the special message to that effect.
314+
expect_err(
315+
config,
316+
&["rustup", "default", "nightly"],
317+
"update not yet available",
318+
);
314319
});
315320
}
316321

0 commit comments

Comments
 (0)