summaryrefslogtreecommitdiff
path: root/src/map.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-03-20 08:46:16 +0200
committerLars Wirzenius <liw@liw.fi>2020-03-20 08:46:16 +0200
commitdcbcbd9457d4bd4d21bcf8dbcc9e416fff463d92 (patch)
treefef50ff7fd2c71e761717c780048bfd29322a87b /src/map.rs
parent97654c1795dfb9e84792713911475310e4bc1a86 (diff)
downloadroadmap-dcbcbd9457d4bd4d21bcf8dbcc9e416fff463d92.tar.gz
Change: make error message for wrong number of goals more helpful
Diffstat (limited to 'src/map.rs')
-rw-r--r--src/map.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/map.rs b/src/map.rs
index 77b2feb..c1294bf 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -27,7 +27,10 @@ impl Roadmap {
// Find steps that nothing depends on.
fn goals(&self) -> Vec<&Step> {
- self.steps.iter().filter(|step| self.is_goal(step)).collect()
+ self.steps
+ .iter()
+ .filter(|step| self.is_goal(step))
+ .collect()
}
/// Count number of steps that nothing depends on.
@@ -125,10 +128,18 @@ impl Roadmap {
// Validate that the parsed, constructed roadmap is valid.
pub fn validate(&self) -> RoadmapResult<()> {
// Is there exactly one goal?
- match self.count_goals() {
+ let goals = self.goals();
+ let n = goals.len();
+ match n {
0 => return Err(format!("the roadmap doesn't have a goal").into()),
1 => (),
- _ => return Err(format!("must have exactly one goal for roadmap").into()),
+ _ => {
+ let mut names: Vec<&str> = goals.iter().map(|s| s.name()).collect();
+ names.sort();
+ let names = names.join(", ");
+ let msg = format!("only one goal allowed, found {}: {}", n, names);
+ return Err(msg.into());
+ }
}
// Does every dependency exist?