diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-03-20 09:27:36 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-03-20 09:30:39 +0200 |
commit | 5e5891771efd0530b1e648c1acb6d673b032e432 (patch) | |
tree | 889930448ab8764dc8f37840da4a07dd750ac3e1 /src/map.rs | |
parent | dcbcbd9457d4bd4d21bcf8dbcc9e416fff463d92 (diff) | |
download | roadmap-5e5891771efd0530b1e648c1acb6d673b032e432.tar.gz |
Change: use anyhow and thiserror for error handling
Diffstat (limited to 'src/map.rs')
-rw-r--r-- | src/map.rs | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1,12 +1,12 @@ -use std::error::Error; use textwrap::fill; pub use crate::from_yaml; +pub use crate::RoadmapError; pub use crate::Status; pub use crate::Step; /// Error in Roadmap, from parsing or otherwise. -pub type RoadmapResult<T> = Result<T, Box<dyn Error>>; +pub type RoadmapResult<T> = Result<T, RoadmapError>; /// Represent a full project roadmap. /// @@ -131,14 +131,14 @@ impl Roadmap { let goals = self.goals(); let n = goals.len(); match n { - 0 => return Err(format!("the roadmap doesn't have a goal").into()), + 0 => return Err(RoadmapError::NoGoals), 1 => (), _ => { - 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()); + let names: Vec<String> = goals.iter().map(|s| s.name().into()).collect(); + return Err(RoadmapError::ManyGoals { + count: n, + names: names, + }); } } @@ -146,11 +146,11 @@ impl Roadmap { for step in self.iter() { for depname in step.dependencies() { match self.get_step(depname) { - None => { - return Err( - format!("step {} depends on missing {}", step.name(), depname).into(), - ) - } + None => + return Err(RoadmapError::MissingDep { + name: step.name().into(), + missing: depname.into(), + }), Some(_) => (), } } |