diff --git a/cmd/soroban-cli/src/config/self_outdated_check.rs b/cmd/soroban-cli/src/config/self_outdated_check.rs index 9146c427e..f1e4e753d 100644 --- a/cmd/soroban-cli/src/config/self_outdated_check.rs +++ b/cmd/soroban-cli/src/config/self_outdated_check.rs @@ -1,8 +1,8 @@ use crate::config::locator; use jsonrpsee_core::Serialize; +use semver::Version; use serde::Deserialize; use std::fs; -use semver::Version; const FILE_NAME: &str = "self_outdated_check.toml"; @@ -73,7 +73,7 @@ mod tests { let saved_check = SelfOutdatedCheck { latest_check_time: 1_234_567_890, max_stable_version: Version::new(1, 2, 3), - max_version: Version::parse("1.2.4-rc.1").unwrap() + max_version: Version::parse("1.2.4-rc.1").unwrap(), }; saved_check.save().unwrap(); let loaded_check = SelfOutdatedCheck::load().unwrap(); diff --git a/cmd/soroban-cli/src/self_outdated_check.rs b/cmd/soroban-cli/src/self_outdated_check.rs index 2b2798ad8..11f6122c5 100644 --- a/cmd/soroban-cli/src/self_outdated_check.rs +++ b/cmd/soroban-cli/src/self_outdated_check.rs @@ -50,20 +50,37 @@ pub fn print_upgrade_prompt() { let current_version = crate::commands::version::pkg(); let print = Print::new(false); - let mut stats = SelfOutdatedCheck::load().unwrap_or_default(); + let mut stats = match SelfOutdatedCheck::load() { + Ok(stats) => stats, + Err(e) => { + print.warnln(format!("Failed to load self outdated check data: {}", e)); + SelfOutdatedCheck::default() + } + }; #[allow(clippy::cast_sign_loss)] let now = chrono::Utc::now().timestamp() as u64; // Skip fetch from crates.io if we've checked recently if now - stats.latest_check_time >= MINIMUM_CHECK_INTERVAL.as_secs() { - if let Ok(c) = fetch_latest_crate_info() { - stats = SelfOutdatedCheck { - latest_check_time: now, - max_stable_version: c.max_stable_version, - max_version: c.max_version, - }; - stats.save().unwrap_or_default(); + match fetch_latest_crate_info() { + Ok(c) => { + stats = SelfOutdatedCheck { + latest_check_time: now, + max_stable_version: c.max_stable_version, + max_version: c.max_version, + }; + } + Err(e) => { + print.warnln(format!("Failed to fetch stellar-cli info from crates.io: {}", e)); + // Only update the latest check time if the fetch failed + // This way we don't spam the user with errors + stats.latest_check_time = now; + } + } + + if let Err(e) = stats.save() { + print.warnln(format!("Failed to save self outdated check data: {}", e)); } }