diff --git a/src-tauri/src/app/watcher/dispatchers/file_change.rs b/src-tauri/src/app/watcher/dispatchers/file_change.rs index 6aeab945c..93412eaca 100644 --- a/src-tauri/src/app/watcher/dispatchers/file_change.rs +++ b/src-tauri/src/app/watcher/dispatchers/file_change.rs @@ -59,9 +59,16 @@ impl Dispatcher { continue; } for file_path in event.paths { - let relative_file_path = - file_path.strip_prefix(&self.project_path).unwrap(); - if let Err(e) = rtx.send(relative_file_path.to_path_buf()) { + if let Err(e) = file_path + .strip_prefix(&self.project_path) + .with_context(|| { + format!( + "failed to striprefix from file path: {}", + file_path.display() + ) + }) + .map(|relative_file_path| rtx.send(relative_file_path.to_path_buf())) + { log::error!( "{}: failed to send file change event: {:#}", self.project_id, diff --git a/src-tauri/src/fs.rs b/src-tauri/src/fs.rs index 0fa990026..6a6c31592 100644 --- a/src-tauri/src/fs.rs +++ b/src-tauri/src/fs.rs @@ -1,9 +1,10 @@ use std::path::{Path, PathBuf}; +use anyhow::Result; use walkdir::WalkDir; // Returns an ordered list of relative paths for files inside a directory recursively. -pub fn list_files>(dir_path: P) -> Result, std::io::Error> { +pub fn list_files>(dir_path: P) -> Result> { let mut files = vec![]; let dir_path = dir_path.as_ref(); if !dir_path.exists() { @@ -13,7 +14,7 @@ pub fn list_files>(dir_path: P) -> Result, std::io:: let entry = entry?; if entry.file_type().is_file() { let path = entry.path(); - let path = path.strip_prefix(dir_path).unwrap(); + let path = path.strip_prefix(dir_path)?; let path = path.to_path_buf(); files.push(path); }