diff --git a/src/main.rs b/src/main.rs index 6398ea3..802f4f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,5 +29,10 @@ mod pathop; fn main() { let args = cli::get_args(); - run::run(args); + if let Err(e) = run::run(args) { + eprintln!("Error: {}", e); + + #[cfg(unix)] + std::process::exit(1) + } } diff --git a/src/run.rs b/src/run.rs index 0128301..5e7b703 100644 --- a/src/run.rs +++ b/src/run.rs @@ -14,6 +14,8 @@ use signal::{self, Signal}; use watcher::{Event, Watcher}; use pathop::PathOp; +type Result = ::std::result::Result>; + fn init_logger(debug: bool) { let mut log_builder = env_logger::LogBuilder::new(); let level = if debug { @@ -28,7 +30,7 @@ fn init_logger(debug: bool) { log_builder.init().expect("unable to initialize logger"); } -pub fn run(args: cli::Args) { +pub fn run(args: cli::Args) -> Result<()> { let child_process: Arc>> = Arc::new(RwLock::new(None)); let weak_child = Arc::downgrade(&child_process); @@ -49,15 +51,16 @@ pub fn run(args: cli::Args) { init_logger(args.debug); - let paths: Vec = args.paths + let paths: Result> = args.paths .iter() .map(|p| { - Path::new(&p) + Ok(Path::new(&p) .canonicalize() - .expect(&format!("unable to canonicalize \"{}\"", &p)) - .to_owned() + .map_err(|e| format!("Unable to canonicalize path: \"{}\", {}", p, e))? + .to_owned()) }) .collect(); + let paths = paths?; let gitignore = if !args.no_vcs_ignore { gitignore::load(&paths) @@ -166,6 +169,7 @@ pub fn run(args: cli::Args) { break; } } + Ok(()) } fn wait_fs(rx: &Receiver, filter: &NotificationFilter, debounce: u64) -> Vec {