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

chore: more error reporting in self-update #823

Merged
merged 1 commit into from
Feb 21, 2024
Merged
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
21 changes: 17 additions & 4 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use flate2::read::GzDecoder;
use tar::Archive;

use miette::IntoDiagnostic;
use miette::{Context, IntoDiagnostic};
use reqwest::Client;
use serde::Deserialize;

Expand Down Expand Up @@ -211,15 +211,28 @@ async fn retrieve_target_version(version: &Option<String>) -> miette::Result<Git
.header("User-Agent", user_agent())
.send()
.await
.expect("Failed to fetch latest version from github");
.expect("Failed to fetch from GitHub, client panic.");

// Catch errors from the GitHub API
if !res.status().is_success() {
return Err(miette::miette!(
"Failed to fetch the release from github, status {}, body: {}",
res.status(),
res.text()
.await
.expect("Failed to fetch GitHub release body, body text panic.")
));
}

let body = res
.text()
.await
.expect("Failed to fetch latest version from github");
.expect("Failed to fetch GitHub release body, body text panic.");

// compare target version with current version
serde_json::from_str::<GithubRelease>(&body).into_diagnostic()
serde_json::from_str::<GithubRelease>(&body)
.into_diagnostic()
.with_context(|| format!("Failed to parse the Release from github: {:#?}", body))
}

fn pixi_binary_name() -> String {
Expand Down
Loading