1use thiserror::Error;
6
7use crate::{DependencyProvider, DerivationTree};
8
9pub type NoSolutionError<DP> = DerivationTree<
11 <DP as DependencyProvider>::P,
12 <DP as DependencyProvider>::VS,
13 <DP as DependencyProvider>::M,
14>;
15
16#[derive(Error)]
18pub enum PubGrubError<DP: DependencyProvider> {
19 #[error("There is no solution")]
21 NoSolution(NoSolutionError<DP>),
22
23 #[error("Retrieving dependencies of {package} {version} failed")]
26 ErrorRetrievingDependencies {
27 package: DP::P,
29 version: DP::V,
31 source: DP::Err,
33 },
34
35 #[error("Choosing a version for {package} failed")]
38 ErrorChoosingVersion {
39 package: DP::P,
41 source: DP::Err,
43 },
44
45 #[error("The solver was cancelled")]
48 ErrorInShouldCancel(#[source] DP::Err),
49}
50
51impl<DP: DependencyProvider> From<NoSolutionError<DP>> for PubGrubError<DP> {
52 fn from(err: NoSolutionError<DP>) -> Self {
53 Self::NoSolution(err)
54 }
55}
56
57impl<DP> std::fmt::Debug for PubGrubError<DP>
58where
59 DP: DependencyProvider,
60{
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 match self {
63 Self::NoSolution(err) => f.debug_tuple("NoSolution").field(&err).finish(),
64 Self::ErrorRetrievingDependencies {
65 package,
66 version,
67 source,
68 } => f
69 .debug_struct("ErrorRetrievingDependencies")
70 .field("package", package)
71 .field("version", version)
72 .field("source", source)
73 .finish(),
74 Self::ErrorChoosingVersion { package, source } => f
75 .debug_struct("ErrorChoosingVersion")
76 .field("package", package)
77 .field("source", source)
78 .finish(),
79 Self::ErrorInShouldCancel(arg0) => {
80 f.debug_tuple("ErrorInShouldCancel").field(arg0).finish()
81 }
82 }
83 }
84}