Skip to content

Commit

Permalink
fix: Add proper error for environment creation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Wackyator committed Feb 26, 2024
1 parent 3af86dc commit 9835650
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions py-rattler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub enum PyRattlerError {
ConversionError(#[from] ConversionError),
#[error("{0}")]
RequirementError(String),
#[error("{0}")]
EnvironmentCreationError(String),
}

impl From<PyRattlerError> for PyErr {
Expand Down Expand Up @@ -100,6 +102,9 @@ impl From<PyRattlerError> for PyErr {
}
PyRattlerError::ConversionError(err) => ConversionException::new_err(err.to_string()),
PyRattlerError::RequirementError(err) => RequirementException::new_err(err),
PyRattlerError::EnvironmentCreationError(err) => {
EnvironmentCreationException::new_err(err)
}
}
}
}
Expand All @@ -124,3 +129,4 @@ create_exception!(exceptions, VersionBumpException, PyException);
create_exception!(exceptions, ParseCondaLockException, PyException);
create_exception!(exceptions, ConversionException, PyException);
create_exception!(exceptions, RequirementException, PyException);
create_exception!(exceptions, EnvironmentCreationException, PyException);
8 changes: 4 additions & 4 deletions py-rattler/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use pep508_rs::Requirement;
use pyo3::{pyclass, pymethods, types::PyBytes, PyErr, PyResult, Python};
use pyo3::{pyclass, pymethods, types::PyBytes, PyResult, Python};
use rattler_conda_types::{MatchSpec, RepoDataRecord};
use rattler_lock::{
Channel, Environment, LockFile, Package, PackageHashes, PypiPackageData,
Expand Down Expand Up @@ -148,9 +148,9 @@ impl PyEnvironment {
Ok(lock
.finish()
.environment(&name)
.ok_or(Into::<PyErr>::into(PyRattlerError::RequirementError(
"Temp Placeholder Error".to_owned(),
)))?
.ok_or(PyRattlerError::EnvironmentCreationError(
"Environment creation failed.".into(),
))?
.into())
}

Expand Down

0 comments on commit 9835650

Please sign in to comment.