Skip to content

Commit

Permalink
Add more error message for conda create env
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Feb 10, 2025
1 parent 28f915a commit 590ba4c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use fs_err as fs;
use maturin::Target;
use normpath::PathExt as _;
Expand Down Expand Up @@ -85,6 +85,7 @@ pub fn maybe_mock_cargo() {
}

/// Better error formatting
#[track_caller]
pub fn handle_result<T>(result: Result<T>) -> T {
match result {
Err(e) => {
Expand Down Expand Up @@ -199,7 +200,21 @@ pub fn create_conda_env(name: &str, major: usize, minor: usize) -> Result<(PathB
.arg("--json")
.output()
.expect("Conda not available.");
let result: CondaCreateResult = serde_json::from_slice(&output.stdout)?;
if !output.status.success() {
panic!(
"Failed to create conda environment: {}\n---stdout:\n{}---stderr:\n{}",
output.status,
str::from_utf8(&output.stdout)?,
str::from_utf8(&output.stderr)?
);
}
let result: CondaCreateResult = serde_json::from_slice(&output.stdout).with_context(|| {
format!(
"Failed to deserialize conda create command output:\n---stdout:\n{}---stderr:\n{}",
str::from_utf8(&output.stdout).unwrap(),
str::from_utf8(&output.stderr).unwrap(),
)
})?;
if !result.success {
bail!("Failed to create conda environment {}.", name);
}
Expand Down

0 comments on commit 590ba4c

Please sign in to comment.