Skip to content

Commit

Permalink
print warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Aug 29, 2024
1 parent 8a28eb8 commit 39efaca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/config/self_outdated_check.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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();
Expand Down
33 changes: 25 additions & 8 deletions cmd/soroban-cli/src/self_outdated_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 39efaca

Please sign in to comment.