Fix panic on permission denial

Also, improve the error messages.
pull/586/head
Arijit Basu 1 year ago
parent da354cbcf9
commit 903e0dda92

@ -139,7 +139,7 @@ Example:
#### FocusPreviousSelection #### FocusPreviousSelection
Focus on the previous item. Focus on the previous selection item.
Example: Example:

@ -608,14 +608,20 @@ impl App {
pub fn explore_pwd(mut self) -> Result<Self> { pub fn explore_pwd(mut self) -> Result<Self> {
let focus = &self.last_focus.get(&self.pwd).cloned().unwrap_or(None); let focus = &self.last_focus.get(&self.pwd).cloned().unwrap_or(None);
let pwd = self.pwd.clone(); let pwd = self.pwd.clone();
self = self.add_last_focus(pwd, focus.clone())?; self = self.add_last_focus(pwd.clone(), focus.clone())?;
let dir = explorer::explore_sync(
match explorer::explore_sync(
self.explorer_config.clone(), self.explorer_config.clone(),
self.pwd.clone().into(), self.pwd.clone().into(),
focus.as_ref().map(PathBuf::from), focus.as_ref().map(PathBuf::from),
self.directory_buffer.as_ref().map(|d| d.focus).unwrap_or(0), 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<Self> { fn explore_pwd_async(mut self) -> Result<Self> {
@ -867,7 +873,7 @@ impl App {
} }
} else { } else {
self.log_error(format!( self.log_error(format!(
"not a valid directory: {}", "not a valid directory: {:?}",
vroot.to_string_lossy() vroot.to_string_lossy()
)) ))
} }
@ -930,7 +936,7 @@ impl App {
} }
self.explore_pwd() 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) Ok(self)
} else { } else {
self.log_error(format!("{name} not found in $PWD")) self.log_error(format!("{name:?} not found in $PWD"))
} }
} else { } else {
Ok(self) Ok(self)
@ -1147,10 +1153,10 @@ impl App {
self.change_directory(&parent.to_string_lossy(), false)? self.change_directory(&parent.to_string_lossy(), false)?
.focus_by_file_name(&filename.to_string_lossy(), save_history) .focus_by_file_name(&filename.to_string_lossy(), save_history)
} else { } else {
self.log_error(format!("{path} not found")) self.log_error(format!("{path:?} not found"))
} }
} else { } 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) { } else if self.config.modes.custom.contains_key(mode) {
self.switch_mode_custom_keeping_input_buffer(mode) self.switch_mode_custom_keeping_input_buffer(mode)
} else { } 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) Ok(self)
} else { } 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) Ok(self)
} else { } 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) { } else if self.config.layouts.custom.contains_key(layout) {
self.switch_layout_custom(layout) self.switch_layout_custom(layout)
} else { } 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) Ok(self)
} else { } 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) Ok(self)
} else { } else {
self.log_error(format!("Custom layout not found: {layout}")) self.log_error(format!("Custom layout not found: {layout:?}"))
} }
} }

@ -110,7 +110,7 @@ pub enum ExternalMsg {
/// - YAML: `FocusPrevious` /// - YAML: `FocusPrevious`
FocusPrevious, FocusPrevious,
/// Focus on the previous item. /// Focus on the previous selection item.
/// ///
/// Example: /// Example:
/// ///

@ -297,12 +297,13 @@ impl Runner {
execute!(stdout, term::EnterAlternateScreen)?; execute!(stdout, term::EnterAlternateScreen)?;
let mut fifo: Option<fs::File> = let mut fifo: Option<fs::File> =
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 // TODO remove duplicate segment
match start_fifo(path, &app.focused_node_str()) { match start_fifo(&path, &app.focused_node_str()) {
Ok(file) => Some(file), Ok(file) => Some(file),
Err(e) => { Err(e) => {
app = app.log_error(e.to_string())?; app = app
.log_error(format!("could not start fifo {path:?}: {e}"))?;
None None
} }
} }
@ -316,7 +317,7 @@ impl Runner {
let mut mouse_enabled = app.config.general.enable_mouse; let mut mouse_enabled = app.config.general.enable_mouse;
if mouse_enabled { if mouse_enabled {
if let Err(e) = execute!(stdout, event::EnableMouseCapture) { 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; mouse_enabled = true;
} }
Err(e) => { 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; mouse_enabled = false;
} }
Err(e) => { 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()) { fifo = match start_fifo(&path, &app.focused_node_str()) {
Ok(file) => Some(file), Ok(file) => Some(file),
Err(e) => { Err(e) => {
app = app.log_error(e.to_string())?; app = app.log_error(format!(
"could not start fifo {path:?}: {e}"
))?;
None None
} }
} }
@ -569,7 +576,9 @@ impl Runner {
{ {
Ok(file) => Some(file), Ok(file) => Some(file),
Err(e) => { Err(e) => {
app = app.log_error(e.to_string())?; app = app.log_error(format!(
"could not toggle fifo {path:?}: {e}"
))?;
None None
} }
} }

Loading…
Cancel
Save