diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-14 17:57:50 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-14 17:57:50 -0400 |
commit | 71e0c7faf3cc283b2b24e70631e5b18a7a7525cd (patch) | |
tree | b27794c91a930ae2a1bc5cdc6a468b9b4d553134 /src/commands/delete_files.rs | |
parent | 5a820a7a275bf5cacd2c545c0a0ac533789ec349 (diff) |
rework error handling system
rather than letting each command separately handle errors, we return a
Result<(), JoshutoError> instead and allow for run.rs to handle all errors
Diffstat (limited to 'src/commands/delete_files.rs')
-rw-r--r-- | src/commands/delete_files.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index f450e57..8f6cacb 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -4,6 +4,7 @@ use std::path; use crate::commands::{self, JoshutoCommand, JoshutoRunnable}; use crate::config::keymap; use crate::context::JoshutoContext; +use crate::error::JoshutoError; use crate::preview; use crate::ui; use crate::window::JoshutoView; @@ -42,7 +43,11 @@ impl std::fmt::Display for DeleteFiles { } impl JoshutoRunnable for DeleteFiles { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + fn execute( + &self, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), JoshutoError> { ui::wprint_msg(&view.bot_win, "Delete selected files? (Y/n)"); ncurses::timeout(-1); ncurses::doupdate(); @@ -54,9 +59,7 @@ impl JoshutoRunnable for DeleteFiles { match Self::remove_files(paths) { Ok(_) => ui::wprint_msg(&view.bot_win, "Deleted files"), Err(e) => { - ui::wprint_err(&view.bot_win, e.to_string().as_str()); - ncurses::doupdate(); - return; + return Err(JoshutoError::IO(e)); } } } @@ -83,5 +86,6 @@ impl JoshutoRunnable for DeleteFiles { let curr_tab = &mut context.tabs[context.curr_tab_index]; preview::preview_file(curr_tab, &view, &context.config_t); ncurses::doupdate(); + Ok(()) } } |