Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align choose version error #317

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,34 @@ pub type NoSolutionError<DP> = DerivationTree<
#[derive(Error)]
pub enum PubGrubError<DP: DependencyProvider> {
/// There is no solution for this set of dependencies.
#[error("No solution")]
#[error("There is no solution")]
NoSolution(NoSolutionError<DP>),

/// Error arising when the implementer of [DependencyProvider] returned an error in the method
/// [get_dependencies](DependencyProvider::get_dependencies).
/// [`get_dependencies`](DependencyProvider::get_dependencies).
#[error("Retrieving dependencies of {package} {version} failed")]
ErrorRetrievingDependencies {
/// Package whose dependencies we want.
package: DP::P,
/// Version of the package for which we want the dependencies.
version: DP::V,
/// Error raised by the implementer of
/// [DependencyProvider].
/// Error raised by the implementer of [DependencyProvider].
source: DP::Err,
},

/// Error arising when the implementer of [DependencyProvider] returned an error in the method
/// [choose_version](DependencyProvider::choose_version).
#[error("Decision making failed")]
ErrorChoosingPackageVersion(#[source] DP::Err),
/// [`choose_version`](DependencyProvider::choose_version).
#[error("Choosing a version for {package} failed")]
ErrorChoosingVersion {
/// Package to choose a version for.
package: DP::P,
/// Error raised by the implementer of [DependencyProvider].
source: DP::Err,
},

/// Error arising when the implementer of [DependencyProvider]
/// returned an error in the method [should_cancel](DependencyProvider::should_cancel).
#[error("We should cancel")]
/// returned an error in the method [`should_cancel`](DependencyProvider::should_cancel).
#[error("The solver was cancelled")]
ErrorInShouldCancel(#[source] DP::Err),
}

Expand All @@ -67,9 +71,10 @@ where
.field("version", version)
.field("source", source)
.finish(),
Self::ErrorChoosingPackageVersion(arg0) => f
.debug_tuple("ErrorChoosingPackageVersion")
.field(arg0)
Self::ErrorChoosingVersion { package, source } => f
.debug_struct("ErrorChoosingVersion")
.field("package", package)
.field("source", source)
.finish(),
Self::ErrorInShouldCancel(arg0) => {
f.debug_tuple("ErrorInShouldCancel").field(arg0).finish()
Expand Down
5 changes: 4 additions & 1 deletion src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ pub fn resolve<DP: DependencyProvider>(

let decision = dependency_provider
.choose_version(&state.package_store[next], term_intersection)
.map_err(PubGrubError::ErrorChoosingPackageVersion)?;
.map_err(|err| PubGrubError::ErrorChoosingVersion {
package: state.package_store[next].clone(),
source: err,
})?;

info!(
"DP chose: {:?} = '{}' @ {:?}",
Expand Down