Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(update): Properly handle errors when getting latest CLI version #2370

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/commands/update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use clap::{Arg, ArgAction, ArgMatches, Command};

use crate::utils::update::{assert_updatable, can_update_sentrycli, get_latest_sentrycli_release};
Expand Down Expand Up @@ -29,7 +29,8 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
assert_updatable()?;

let exe = env::current_exe()?;
let update = get_latest_sentrycli_release()?;
let update = get_latest_sentrycli_release()
.with_context(|| "Error getting latest Sentry CLI version.")?;
if !update.have_version_info() {
bail!("Could not get the latest release version.");
}
Expand Down
7 changes: 4 additions & 3 deletions src/utils/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl LastUpdateCheck {
}
}

#[derive(Default)]
pub struct SentryCliUpdateInfo {
latest_release: Option<SentryCliRelease>,
}
Expand Down Expand Up @@ -176,11 +177,10 @@ impl SentryCliUpdateInfo {
}
}

#[expect(clippy::unnecessary_wraps)]
pub fn get_latest_sentrycli_release() -> Result<SentryCliUpdateInfo> {
let api = Api::current();
Ok(SentryCliUpdateInfo {
latest_release: api.get_latest_sentrycli_release().unwrap_or_default(),
latest_release: api.get_latest_sentrycli_release()?,
})
}

Expand Down Expand Up @@ -224,7 +224,8 @@ fn update_nagger_impl() -> Result<()> {

if check.should_run_check() {
info!("Running update nagger update check");
let ui = get_latest_sentrycli_release()?;
// Error getting latest version in update nagger should not crash the CLI
let ui = get_latest_sentrycli_release().unwrap_or_default();
if ui.have_version_info() {
check.update_for_info(&ui);
let mut f = fs::File::create(&path)?;
Expand Down
Loading