Add AppError
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 21m29s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 21m29s
This commit is contained in:
parent
f4694157ab
commit
df99ef3a3f
4 changed files with 47 additions and 22 deletions
|
@ -7,7 +7,15 @@ pub enum AppExit {
|
|||
Error(Box<dyn Error>),
|
||||
}
|
||||
|
||||
pub type RunnerFn = Box<dyn FnOnce() -> AppExit>;
|
||||
pub type RunnerFn = Box<dyn FnOnce(App) -> AppExit>;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AppError {
|
||||
#[error("Runner is not set")]
|
||||
RunnerNotSet,
|
||||
#[error("Runner returned an error : {0}")]
|
||||
RunnerError(Box<dyn Error>),
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
world: World,
|
||||
|
@ -35,16 +43,13 @@ impl App {
|
|||
&self.world
|
||||
}
|
||||
|
||||
pub fn run(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
pub fn run(mut self) -> Result<(), AppError> {
|
||||
match self.runner.take() {
|
||||
Some(runner) => match runner() {
|
||||
Some(runner) => match runner(self) {
|
||||
AppExit::Success => Ok(()),
|
||||
AppExit::Error(e) => Err(e),
|
||||
AppExit::Error(e) => Err(AppError::RunnerError(e)),
|
||||
},
|
||||
None => Err(Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"runner is not set",
|
||||
))),
|
||||
None => Err(AppError::RunnerNotSet),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue