From 98356507cb62952c3689520c93d1ff2f362b0b24 Mon Sep 17 00:00:00 2001 From: Wackyator Date: Mon, 26 Feb 2024 20:31:48 +0530 Subject: [PATCH] fix: Add proper error for environment creation failure --- py-rattler/src/error.rs | 6 ++++++ py-rattler/src/lock/mod.rs | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/py-rattler/src/error.rs b/py-rattler/src/error.rs index e81c79695..b455be49e 100644 --- a/py-rattler/src/error.rs +++ b/py-rattler/src/error.rs @@ -57,6 +57,8 @@ pub enum PyRattlerError { ConversionError(#[from] ConversionError), #[error("{0}")] RequirementError(String), + #[error("{0}")] + EnvironmentCreationError(String), } impl From for PyErr { @@ -100,6 +102,9 @@ impl From 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) + } } } } @@ -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); diff --git a/py-rattler/src/lock/mod.rs b/py-rattler/src/lock/mod.rs index f40947405..5c86fb2e7 100644 --- a/py-rattler/src/lock/mod.rs +++ b/py-rattler/src/lock/mod.rs @@ -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, @@ -148,9 +148,9 @@ impl PyEnvironment { Ok(lock .finish() .environment(&name) - .ok_or(Into::::into(PyRattlerError::RequirementError( - "Temp Placeholder Error".to_owned(), - )))? + .ok_or(PyRattlerError::EnvironmentCreationError( + "Environment creation failed.".into(), + ))? .into()) }