From 36a34207e7e9441093e909bb2cf6ddd2634fb6ee Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 9 May 2016 20:24:31 -0700 Subject: [PATCH] Added error for downloading bogus versions --- src/rustup-dist/src/dist.rs | 12 ++++++++---- src/rustup-utils/src/errors.rs | 6 ++++++ tests/cli-self-update.rs | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index a1d3ca351b5..0f4c93f33b7 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -432,10 +432,14 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>, toolchain.manifest_name())); } }; - match try!(manifestation.update_v1(&manifest, update_hash, - &download.temp_cfg, download.notify_handler.clone())) { - None => Ok(None), - Some(hash) => Ok(Some(hash)), + match manifestation.update_v1(&manifest, update_hash, + &download.temp_cfg, download.notify_handler.clone()) { + Ok(None) => Ok(None), + Ok(Some(hash)) => Ok(Some(hash)), + Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::Download404 { .. }), e)) => { + Err(Error(ErrorKind::Utils(rustup_utils::ErrorKind::Download404BadVers { vers: toolchain_str }), e)) + }, + Err(e) => Err(e) } } diff --git a/src/rustup-utils/src/errors.rs b/src/rustup-utils/src/errors.rs index 1c54032e638..ad929cf9194 100644 --- a/src/rustup-utils/src/errors.rs +++ b/src/rustup-utils/src/errors.rs @@ -78,6 +78,12 @@ error_chain! { description("could not download file") display("could not download file from '{}' to '{}", url, path.display()) } + Download404BadVers { + vers: String + } { + description("could not download nonexistent rust version") + display("could not download nonexistent rust version `{}`", vers) + } Download404 { url: hyper::Url, path: PathBuf, diff --git a/tests/cli-self-update.rs b/tests/cli-self-update.rs index ff259ce139b..eb190ef6092 100644 --- a/tests/cli-self-update.rs +++ b/tests/cli-self-update.rs @@ -588,6 +588,15 @@ fn update_download_404() { }); } +#[test] +fn update_bogus_version() { + update_setup(&|config, self_dist| { + expect_ok(config, &["rustup-init", "-y"]); + expect_err(config, &["rustup", "update", "1.0.0-alpha"], + "could not download nonexistent rust version `1.0.0-alpha`"); + }); +} + // Check that multirust.exe has changed after the update. This // is hard for windows because the running process needs to exit // before the new updater can delete it.