From abd8ccefa4fd1abbf674f479f0dd7d0457c94d2d Mon Sep 17 00:00:00 2001 From: Bernardo Date: Wed, 16 Jan 2019 18:42:55 +0100 Subject: better error handling --- crates/ra_vfs/src/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'crates/ra_vfs/src') diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 3eeec8b1c..f698e3e86 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs @@ -86,7 +86,7 @@ pub struct Vfs { pending_changes: Vec, worker: io::Worker, worker_handle: WorkerHandle, - watcher: Watcher, + watcher: Option, } impl fmt::Debug for Vfs { @@ -99,7 +99,13 @@ impl Vfs { pub fn new(mut roots: Vec) -> (Vfs, Vec) { let (worker, worker_handle) = io::start(); - let watcher = Watcher::start(worker.inp.clone()).unwrap(); // TODO return Result? + let watcher = match Watcher::start(worker.inp.clone()) { + Ok(watcher) => Some(watcher), + Err(e) => { + log::error!("could not start watcher: {}", e); + None + } + }; let mut res = Vfs { roots: Arena::default(), @@ -134,7 +140,11 @@ impl Vfs { filter: Box::new(filter), }; res.worker.inp.send(task).unwrap(); - res.watcher.watch(path).unwrap(); + if let Some(ref mut watcher) = res.watcher { + if let Err(e) = watcher.watch(path) { + log::warn!("could not watch \"{}\": {}", path.display(), e); + } + } } let roots = res.roots.iter().map(|(id, _)| id).collect(); (res, roots) @@ -350,7 +360,9 @@ impl Vfs { /// Sutdown the VFS and terminate the background watching thread. pub fn shutdown(self) -> thread::Result<()> { - let _ = self.watcher.shutdown(); + if let Some(watcher) = self.watcher { + let _ = watcher.shutdown(); + } let _ = self.worker.shutdown(); self.worker_handle.shutdown() } -- cgit v1.2.3