mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
don't panic on missing folder
issue #71 - Add some basic error handling - Convert missing folder panic to error
This commit is contained in:
parent
b9822266db
commit
31b5e56959
@ -29,5 +29,10 @@ mod pathop;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = cli::get_args();
|
let args = cli::get_args();
|
||||||
run::run(args);
|
if let Err(e) = run::run(args) {
|
||||||
|
eprintln!("Error: {}", e);
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
std::process::exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
14
src/run.rs
14
src/run.rs
@ -14,6 +14,8 @@ use signal::{self, Signal};
|
|||||||
use watcher::{Event, Watcher};
|
use watcher::{Event, Watcher};
|
||||||
use pathop::PathOp;
|
use pathop::PathOp;
|
||||||
|
|
||||||
|
type Result<T> = ::std::result::Result<T, Box<::std::error::Error>>;
|
||||||
|
|
||||||
fn init_logger(debug: bool) {
|
fn init_logger(debug: bool) {
|
||||||
let mut log_builder = env_logger::LogBuilder::new();
|
let mut log_builder = env_logger::LogBuilder::new();
|
||||||
let level = if debug {
|
let level = if debug {
|
||||||
@ -28,7 +30,7 @@ fn init_logger(debug: bool) {
|
|||||||
log_builder.init().expect("unable to initialize logger");
|
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<RwLock<Option<Process>>> = Arc::new(RwLock::new(None));
|
let child_process: Arc<RwLock<Option<Process>>> = Arc::new(RwLock::new(None));
|
||||||
let weak_child = Arc::downgrade(&child_process);
|
let weak_child = Arc::downgrade(&child_process);
|
||||||
|
|
||||||
@ -49,15 +51,16 @@ pub fn run(args: cli::Args) {
|
|||||||
|
|
||||||
init_logger(args.debug);
|
init_logger(args.debug);
|
||||||
|
|
||||||
let paths: Vec<PathBuf> = args.paths
|
let paths: Result<Vec<PathBuf>> = args.paths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
Path::new(&p)
|
Ok(Path::new(&p)
|
||||||
.canonicalize()
|
.canonicalize()
|
||||||
.expect(&format!("unable to canonicalize \"{}\"", &p))
|
.map_err(|e| format!("Unable to canonicalize path: \"{}\", {}", p, e))?
|
||||||
.to_owned()
|
.to_owned())
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
let paths = paths?;
|
||||||
|
|
||||||
let gitignore = if !args.no_vcs_ignore {
|
let gitignore = if !args.no_vcs_ignore {
|
||||||
gitignore::load(&paths)
|
gitignore::load(&paths)
|
||||||
@ -166,6 +169,7 @@ pub fn run(args: cli::Args) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_fs(rx: &Receiver<Event>, filter: &NotificationFilter, debounce: u64) -> Vec<PathOp> {
|
fn wait_fs(rx: &Receiver<Event>, filter: &NotificationFilter, debounce: u64) -> Vec<PathOp> {
|
||||||
|
Loading…
Reference in New Issue
Block a user