Skip to content

Commit 7eba73a

Browse files
committed
Move error mapping out of validation function
1 parent 49cf657 commit 7eba73a

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

src/cli/self_update.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -140,32 +140,19 @@ impl<'a> InstallOpts<'a> {
140140
fn validate(&self) -> Result<()> {
141141
common::warn_if_host_is_emulated();
142142

143-
// Verify that the installation options are vaguely sane
144-
(|| {
145-
let host_triple = self
146-
.default_host_triple
147-
.as_ref()
148-
.map(dist::TargetTriple::new)
149-
.unwrap_or_else(TargetTriple::from_host_or_build);
150-
let partial_channel = match &self.default_toolchain {
151-
None | Some(MaybeOfficialToolchainName::None) => {
152-
ResolvableToolchainName::try_from("stable")?
153-
}
154-
Some(MaybeOfficialToolchainName::Some(s)) => s.into(),
155-
};
156-
let resolved = partial_channel.resolve(&host_triple)?;
157-
debug!("Successfully resolved installation toolchain as: {resolved}");
158-
Ok(())
159-
})()
160-
.map_err(|e: Box<dyn std::error::Error>| {
161-
anyhow!(
162-
"Pre-checks for host and toolchain failed: {}\n\
163-
If you are unsure of suitable values, the 'stable' toolchain is the default.\n\
164-
Valid host triples look something like: {}",
165-
e,
166-
TargetTriple::from_host_or_build()
167-
)
168-
})?;
143+
let host_triple = self
144+
.default_host_triple
145+
.as_ref()
146+
.map(dist::TargetTriple::new)
147+
.unwrap_or_else(TargetTriple::from_host_or_build);
148+
let partial_channel = match &self.default_toolchain {
149+
None | Some(MaybeOfficialToolchainName::None) => {
150+
ResolvableToolchainName::try_from("stable")?
151+
}
152+
Some(MaybeOfficialToolchainName::Some(s)) => s.into(),
153+
};
154+
let resolved = partial_channel.resolve(&host_triple)?;
155+
debug!("Successfully resolved installation toolchain as: {resolved}");
169156
Ok(())
170157
}
171158
}
@@ -456,7 +443,14 @@ pub(crate) async fn install(
456443
do_pre_install_sanity_checks(no_prompt)?;
457444
}
458445

459-
opts.validate()?;
446+
opts.validate().map_err(|e| {
447+
anyhow!(
448+
"Pre-checks for host and toolchain failed: {e}\n\
449+
If you are unsure of suitable values, the 'stable' toolchain is the default.\n\
450+
Valid host triples look something like: {}",
451+
TargetTriple::from_host_or_build()
452+
)
453+
})?;
460454

461455
if !process()
462456
.var_os("RUSTUP_INIT_SKIP_EXISTENCE_CHECKS")

0 commit comments

Comments
 (0)