diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-03-20 08:46:16 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-03-20 08:46:16 +0200 |
commit | dcbcbd9457d4bd4d21bcf8dbcc9e416fff463d92 (patch) | |
tree | fef50ff7fd2c71e761717c780048bfd29322a87b /src/map.rs | |
parent | 97654c1795dfb9e84792713911475310e4bc1a86 (diff) | |
download | roadmap-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.rs | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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? |