From 7690fc35a9d974461a5b01d39448d921e1330893 Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 7 Jul 2024 12:31:54 +0800 Subject: [PATCH] feat(dist): refine suggestions regarding manifest checksum mismatches --- src/config.rs | 2 +- src/dist/mod.rs | 27 ++++++++++++++++++++++----- tests/suite/cli_v2.rs | 5 +---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6eb51a4ff7c..a1bcbca42d9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -940,7 +940,7 @@ impl<'a> Cfg<'a> { } } -fn dist_root_server(process: &Process) -> Cow<'static, str> { +pub(crate) fn dist_root_server(process: &Process) -> Cow<'static, str> { process .var("RUSTUP_DIST_SERVER") .ok() diff --git a/src/dist/mod.rs b/src/dist/mod.rs index a8180900b90..468a31a2922 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -10,10 +10,13 @@ use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use thiserror::Error as ThisError; -use tracing::info; +use tracing::{info, warn}; use crate::{ - config::Cfg, currentprocess::Process, errors::RustupError, toolchain::ToolchainName, + config::{dist_root_server, Cfg}, + currentprocess::Process, + errors::RustupError, + toolchain::ToolchainName, utils::utils, }; @@ -1166,9 +1169,23 @@ pub(crate) async fn dl_v2_manifest( Ok(Some((manifest, manifest_hash))) } Err(any) => { - if let Some(RustupError::ChecksumFailed { .. }) = any.downcast_ref::() { - // Checksum failed - issue warning to try again later - info!("update not yet available, sorry! try again later") + if let Some(err @ RustupError::ChecksumFailed { .. }) = + any.downcast_ref::() + { + // Manifest checksum mismatched. + warn!("{err}"); + + let server = dist_root_server(download.process); + if server == DEFAULT_DIST_SERVER { + // This might indicate a transient state during an update + // on the official release server + // (see ) + info!("this is likely due to an ongoing update of the official release server, please try again later"); + } else { + // This could also indicate a misconfiguration of a third-party release server + // (see ). + info!("this might indicate an issue with your third-party release server `{server}`"); + } } Err(any) } diff --git a/tests/suite/cli_v2.rs b/tests/suite/cli_v2.rs index 57e9424abf9..1554fe7056f 100644 --- a/tests/suite/cli_v2.rs +++ b/tests/suite/cli_v2.rs @@ -358,10 +358,7 @@ async fn bad_sha_on_manifest() { rustup::utils::raw::write_file(&sha_file, &sha_str).unwrap(); // We fail because the sha is bad, but we should emit the special message to that effect. cx.config - .expect_err( - &["rustup", "default", "nightly"], - "update not yet available", - ) + .expect_err(&["rustup", "default", "nightly"], "please try again later") .await; }