diff --git a/yen-rs/src/commands/create.rs b/yen-rs/src/commands/create.rs index 5bc5a47..87c3426 100644 --- a/yen-rs/src/commands/create.rs +++ b/yen-rs/src/commands/create.rs @@ -33,7 +33,11 @@ pub async fn create_env( .into_diagnostic()?; if !stdout.status.success() { - miette::bail!("Error: unable to create venv!"); + miette::bail!(format!( + "Error: unable to create venv!\nStdout: {}\nStderr: {}", + String::from_utf8_lossy(&stdout.stdout), + String::from_utf8_lossy(&stdout.stderr), + )); } eprintln!( diff --git a/yen-rs/src/github.rs b/yen-rs/src/github.rs index 8c7dda8..54c3b47 100644 --- a/yen-rs/src/github.rs +++ b/yen-rs/src/github.rs @@ -114,15 +114,33 @@ impl MachineSuffix { } async fn get_latest_python_release() -> miette::Result> { - Ok(YEN_CLIENT + let response = YEN_CLIENT .get(*GITHUB_API_URL) .send() .await - .into_diagnostic()? - .json::() - .await - .into_diagnostic()? - .into()) + .into_diagnostic()?; + + // Check if the response status is successful + // Log the response body if the status is not successful + let status_code = response.status().as_u16(); + let success = response.status().is_success(); + let body = response.text().await.into_diagnostic()?; + if !success { + log::error!("Error response: {}\nStatus Code: {}", body, status_code); + miette::bail!("Non-successful API response, check the logs for more info."); + } + + // Attempt to parse the JSON + let github_resp = match serde_json::from_str::(&body) { + Ok(data) => data, + Err(err) => { + // Log the error and response body in case of JSON decoding failure + log::error!("Error decoding JSON: {}", err); + log::error!("Response body: {}", body); + miette::bail!("JSON decoding error, check the logs for more info."); + } + }; + Ok(github_resp.into()) } pub async fn list_pythons() -> miette::Result> {