From 903e0dda92a04cdb5ee35cc144dfa8085c75fed7 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Mon, 30 Jan 2023 20:07:41 +0530 Subject: [PATCH] Fix panic on permission denial Also, improve the error messages. --- docs/en/src/messages.md | 2 +- src/app.rs | 36 +++++++++++++++++++++--------------- src/msg/in_/external.rs | 2 +- src/runner.rs | 25 +++++++++++++++++-------- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/docs/en/src/messages.md b/docs/en/src/messages.md index 34c40ae..43f2ec8 100644 --- a/docs/en/src/messages.md +++ b/docs/en/src/messages.md @@ -139,7 +139,7 @@ Example: #### FocusPreviousSelection -Focus on the previous item. +Focus on the previous selection item. Example: diff --git a/src/app.rs b/src/app.rs index 17709cb..842bb44 100644 --- a/src/app.rs +++ b/src/app.rs @@ -608,14 +608,20 @@ impl App { pub fn explore_pwd(mut self) -> Result { let focus = &self.last_focus.get(&self.pwd).cloned().unwrap_or(None); let pwd = self.pwd.clone(); - self = self.add_last_focus(pwd, focus.clone())?; - let dir = explorer::explore_sync( + self = self.add_last_focus(pwd.clone(), focus.clone())?; + + match explorer::explore_sync( self.explorer_config.clone(), self.pwd.clone().into(), focus.as_ref().map(PathBuf::from), self.directory_buffer.as_ref().map(|d| d.focus).unwrap_or(0), - )?; - self.set_directory(dir) + ) { + Ok(dir) => self.set_directory(dir), + Err(e) => { + self.directory_buffer = None; + self.log_error(format!("Failed to explore {pwd:?}: {e}")) + } + } } fn explore_pwd_async(mut self) -> Result { @@ -867,7 +873,7 @@ impl App { } } else { self.log_error(format!( - "not a valid directory: {}", + "not a valid directory: {:?}", vroot.to_string_lossy() )) } @@ -930,7 +936,7 @@ impl App { } self.explore_pwd() } - Err(e) => self.log_error(e.to_string()), + Err(e) => self.log_error(format!("failed to enter {dir:?}: {e}")), } } @@ -1113,7 +1119,7 @@ impl App { } Ok(self) } else { - self.log_error(format!("{name} not found in $PWD")) + self.log_error(format!("{name:?} not found in $PWD")) } } else { Ok(self) @@ -1147,10 +1153,10 @@ impl App { self.change_directory(&parent.to_string_lossy(), false)? .focus_by_file_name(&filename.to_string_lossy(), save_history) } else { - self.log_error(format!("{path} not found")) + self.log_error(format!("{path:?} not found")) } } else { - self.log_error(format!("Cannot focus on {path}")) + self.log_error(format!("Cannot focus on {path:?}")) } } @@ -1198,7 +1204,7 @@ impl App { } else if self.config.modes.custom.contains_key(mode) { self.switch_mode_custom_keeping_input_buffer(mode) } else { - self.log_error(format!("Mode not found: {mode}")) + self.log_error(format!("Mode not found: {mode:?}")) } } @@ -1223,7 +1229,7 @@ impl App { Ok(self) } else { - self.log_error(format!("Builtin mode not found: {mode}")) + self.log_error(format!("Builtin mode not found: {mode:?}")) } } @@ -1248,7 +1254,7 @@ impl App { Ok(self) } else { - self.log_error(format!("Custom mode not found: {mode}")) + self.log_error(format!("Custom mode not found: {mode:?}")) } } @@ -1258,7 +1264,7 @@ impl App { } else if self.config.layouts.custom.contains_key(layout) { self.switch_layout_custom(layout) } else { - self.log_error(format!("Layout not found: {layout}")) + self.log_error(format!("Layout not found: {layout:?}")) } } @@ -1274,7 +1280,7 @@ impl App { Ok(self) } else { - self.log_error(format!("Builtin layout not found: {layout}")) + self.log_error(format!("Builtin layout not found: {layout:?}")) } } @@ -1290,7 +1296,7 @@ impl App { Ok(self) } else { - self.log_error(format!("Custom layout not found: {layout}")) + self.log_error(format!("Custom layout not found: {layout:?}")) } } diff --git a/src/msg/in_/external.rs b/src/msg/in_/external.rs index 13ff06f..7788fe1 100644 --- a/src/msg/in_/external.rs +++ b/src/msg/in_/external.rs @@ -110,7 +110,7 @@ pub enum ExternalMsg { /// - YAML: `FocusPrevious` FocusPrevious, - /// Focus on the previous item. + /// Focus on the previous selection item. /// /// Example: /// diff --git a/src/runner.rs b/src/runner.rs index 44117bc..a27db30 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -297,12 +297,13 @@ impl Runner { execute!(stdout, term::EnterAlternateScreen)?; let mut fifo: Option = - if let Some(path) = app.config.general.start_fifo.as_ref() { + if let Some(path) = app.config.general.start_fifo.clone() { // TODO remove duplicate segment - match start_fifo(path, &app.focused_node_str()) { + match start_fifo(&path, &app.focused_node_str()) { Ok(file) => Some(file), Err(e) => { - app = app.log_error(e.to_string())?; + app = app + .log_error(format!("could not start fifo {path:?}: {e}"))?; None } } @@ -316,7 +317,7 @@ impl Runner { let mut mouse_enabled = app.config.general.enable_mouse; if mouse_enabled { if let Err(e) = execute!(stdout, event::EnableMouseCapture) { - app = app.log_error(e.to_string())?; + app = app.log_error(format!("could not enable mouse: {e}"))?; } } @@ -508,7 +509,9 @@ impl Runner { mouse_enabled = true; } Err(e) => { - app = app.log_error(e.to_string())?; + app = app.log_error(format!( + "could not enable mouse: {e}" + ))?; } } } @@ -536,7 +539,9 @@ impl Runner { mouse_enabled = false; } Err(e) => { - app = app.log_error(e.to_string())?; + app = app.log_error(format!( + "could not disable mouse: {e}" + ))?; } } } @@ -546,7 +551,9 @@ impl Runner { fifo = match start_fifo(&path, &app.focused_node_str()) { Ok(file) => Some(file), Err(e) => { - app = app.log_error(e.to_string())?; + app = app.log_error(format!( + "could not start fifo {path:?}: {e}" + ))?; None } } @@ -569,7 +576,9 @@ impl Runner { { Ok(file) => Some(file), Err(e) => { - app = app.log_error(e.to_string())?; + app = app.log_error(format!( + "could not toggle fifo {path:?}: {e}" + ))?; None } }