From 1d46e0e0253998c999d3843c6105e5ad17d31af8 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Mon, 5 Jun 2023 10:25:18 +0200 Subject: [PATCH] feat: add libsolve errors to error message --- crates/rattler_solve/src/lib.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/rattler_solve/src/lib.rs b/crates/rattler_solve/src/lib.rs index 324fd304b..13bde9aee 100644 --- a/crates/rattler_solve/src/lib.rs +++ b/crates/rattler_solve/src/lib.rs @@ -10,6 +10,7 @@ pub use libsolv::{ cache_repodata as cache_libsolv_repodata, LibcByteSlice, LibsolvBackend, LibsolvRepoData, }; pub use solver_backend::SolverBackend; +use std::fmt; use rattler_conda_types::GenericVirtualPackage; use rattler_conda_types::{MatchSpec, RepoDataRecord}; @@ -18,16 +19,31 @@ use rattler_conda_types::{MatchSpec, RepoDataRecord}; #[derive(thiserror::Error, Debug)] pub enum SolveError { /// There is no set of dependencies that satisfies the requirements - #[error("unsolvable")] Unsolvable(Vec), /// The solver backend returned operations that we dont know how to install. /// Each string is a somewhat user-friendly representation of which operation was not recognized /// and can be used for error reporting - #[error("unsupported operations")] UnsupportedOperations(Vec), } +impl fmt::Display for SolveError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + SolveError::Unsolvable(operations) => { + write!( + f, + "Cannot solve the request because of: {}", + operations.join(", ") + ) + } + SolveError::UnsupportedOperations(operations) => { + write!(f, "Unsupported operations: {}", operations.join(", ")) + } + } + } +} + /// Represents a dependency resolution task, to be solved by one of the backends (currently only /// libsolv is supported) pub struct SolverTask {