diff --git a/src/app.rs b/src/app.rs index 6f22ae1..8c9a570 100644 --- a/src/app.rs +++ b/src/app.rs @@ -638,9 +638,9 @@ impl App { } } - pub fn task_delete(&self) { + pub fn task_delete(&self) -> Result<(), String> { if self.tasks.len() == 0 { - return + return Ok(()) } let selected = self.state.selected().unwrap_or_default(); let task_id = self.tasks[selected].id().unwrap_or_default(); @@ -649,13 +649,11 @@ impl App { .arg("rc.confirmation=off") .arg("delete") .arg(format!("{}", task_id)) - .output() - .expect( - &format!( - "Cannot run `task delete` for task `{}`. Check documentation for more information", - task_id - )[..], - ); + .output(); + match output { + Ok(_) => Ok(()), + Err(_) => Err(format!("Cannot run `task delete` for task `{}`. Check documentation for more information",task_id)), + } } pub fn task_done(&mut self) { diff --git a/src/main.rs b/src/main.rs index 3d3247c..8dbb848 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,13 @@ fn main() -> Result<(), Box> { Key::Down | Key::Char('j') => app.next(), Key::Up | Key::Char('k') => app.previous(), Key::Char('d') => app.task_done(), - Key::Char('x') => app.task_delete(), + Key::Char('x') => match app.task_delete() { + Ok(_) => (), + Err(e) => { + app.mode = AppMode::TaskError; + app.error = e; + } + }, Key::Char('s') => match app.task_start_or_stop() { Ok(_) => (), Err(e) => {