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

Deal cleanly with malformed default-host #1578

Merged
merged 7 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Remove panic on malformed default host
It is better to report errors cleanly rather than panic.  If the
default-host is set badly then we can end up panicking because
we're unable to parse it.  Since default-host is user input, it's
better we don't panic.
  • Loading branch information
kinnison committed Jan 16, 2019
commit 26972a5329efc0e08f11fb96258d5ad0d18944c7
28 changes: 21 additions & 7 deletions src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 291,25 @@ impl PartialToolchainDesc {
}
}

pub fn resolve(self, host: &TargetTriple) -> ToolchainDesc {
let host = PartialTargetTriple::from_str(&host.0)
.expect("host triple couldn't be converted to partial triple");
let host_arch = host.arch.expect("");
let host_os = host.os.expect("");
pub fn resolve(self, input_host: &TargetTriple) -> Result<ToolchainDesc> {
let host = PartialTargetTriple::from_str(&input_host.0).ok_or_else(|| {
format!(
"Provided host '{}' couldn't be converted to partial triple",
input_host.0
)
})?;
let host_arch = host.arch.ok_or_else(|| {
format!(
"Provided host '{}' did not specify a CPU architecture",
input_host.0
)
})?;
let host_os = host.os.ok_or_else(|| {
format!(
"Provided host '{}' did not specify an operating system",
input_host.0
)
})?;
let host_env = host.env;

// If OS was specified, don't default to host environment, even if the OS matches
Expand All @@ -314,11 328,11 @@ impl PartialToolchainDesc {
format!("{}-{}", arch, os)
};

ToolchainDesc {
Ok(ToolchainDesc {
channel: self.channel,
date: self.date,
target: TargetTriple(trip),
}
})
}

pub fn has_triple(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 493,7 @@ impl Cfg {
pub fn resolve_toolchain(&self, name: &str) -> Result<String> {
if let Ok(desc) = dist::PartialToolchainDesc::from_str(name) {
let host = self.get_default_host_triple()?;
Ok(desc.resolve(&host).to_string())
Ok(desc.resolve(&host)?.to_string())
} else {
Ok(name.to_owned())
}
Expand Down