Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jrray committed Aug 26, 2024
1 parent e18064f commit acb227e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/spk-solve/crates/graph/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,24 @@ impl FormatError for Error {
let mut msg = String::new();
msg.push_str("Failed to resolve");
match self {
Error::FailedToResolve(_graph) => {
Error::FailedToResolve(graph) => {
// TODO: provide a summary based on the graph
msg.push_str(
": there is no solution for these requests using the available packages",
);
msg.push_str("\n * TODO: provide a summary based on the graph");
let root = graph.root.read().await;
for d in root.output_decisions() {
msg.push_str("\n * D");
for c in &d.changes {
msg.push_str("\n C: ");
msg.push_str(format!("{c:?}").as_str());
}
for n in &d.notes {
msg.push_str("\n N: ");
msg.push_str(format!("{n:?}").as_str());
}
}
}
Error::SolverError(reason) => {
msg.push_str("\n * ");
Expand Down
4 changes: 4 additions & 0 deletions crates/spk-solve/crates/graph/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ impl Node {
)),
);
}

pub fn output_decisions(&self) -> impl Iterator<Item = &Arc<Decision>> {
self.outputs_decisions.iter()
}
}

/// Some additional information left by the solver
Expand Down
28 changes: 28 additions & 0 deletions crates/spk-solve/src/solver_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Arc;
use rstest::{fixture, rstest};
use spfs::encoding::EMPTY_DIGEST;
use spk_schema::foundation::fixtures::*;
use spk_schema::foundation::format::FormatError;
use spk_schema::foundation::ident_component::Component;
use spk_schema::foundation::opt_name;
use spk_schema::ident::{
Expand Down Expand Up @@ -2541,3 +2542,30 @@ async fn test_version_number_masking(
);
assert_ne!(resolved.spec.ident().build(), &Build::Source);
}

#[rstest]
#[tokio::test]
async fn test_solver_error_messages(mut solver: Solver) {
let options = option_map! {};
let repo = make_repo!(
[
{"pkg": "pkg-a/0.9.0"},
{"pkg": "pkg-a/1.0.0"},
{"pkg": "pkg-a/1.2.0"},
{"pkg": "pkg-a/1.2.1"},
{"pkg": "pkg-a/2.0.0"},
{"pkg": "pkg-b/1.0.0", "install": {"requirements": [{"pkg": "pkg-a/>2.0"}]}},
]
);

solver.update_options(options);
solver.add_repository(Arc::new(repo));
solver.add_request(request!("pkg-b/1.0"));

let err = run_and_print_resolve_for_tests(&solver)
.await
.expect_err("Expected solve to fail");
let msg = err.format_error(u8::MAX).await;
eprintln!("\n--->\n{msg}\n<---\n");
assert_eq!(msg, "fudge");
}

0 comments on commit acb227e

Please sign in to comment.