Skip to content

Commit

Permalink
Add logs for venv creation or api decode failure (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani authored Dec 19, 2023
1 parent 870840b commit 3951d7b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
6 changes: 5 additions & 1 deletion yen-rs/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
30 changes: 24 additions & 6 deletions yen-rs/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,33 @@ impl MachineSuffix {
}

async fn get_latest_python_release() -> miette::Result<Vec<String>> {
Ok(YEN_CLIENT
let response = YEN_CLIENT
.get(*GITHUB_API_URL)
.send()
.await
.into_diagnostic()?
.json::<GithubResp>()
.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::<GithubResp>(&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<BTreeMap<Version, String>> {
Expand Down

0 comments on commit 3951d7b

Please sign in to comment.