Log fs watch/unwatch errors harder (to reveal paths)

This commit is contained in:
Félix Saparelli 2021-08-23 05:15:55 +12:00
parent 6cb3fc1c9a
commit 3588cb4d62
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474

View file

@ -7,7 +7,7 @@ use std::{
use notify::Watcher as _; use notify::Watcher as _;
use tokio::sync::{mpsc, watch}; use tokio::sync::{mpsc, watch};
use tracing::{debug, trace}; use tracing::{debug, error, trace};
use crate::{ use crate::{
error::{CriticalError, RuntimeError}, error::{CriticalError, RuntimeError},
@ -157,6 +157,7 @@ pub async fn worker(
for path in to_drop { for path in to_drop {
trace!(?path, "removing path from the watcher"); trace!(?path, "removing path from the watcher");
if let Err(err) = w.unwatch(&path) { if let Err(err) = w.unwatch(&path) {
error!(?err, "notify unwatch() error");
errors errors
.send(RuntimeError::FsWatcherPathRemove { .send(RuntimeError::FsWatcherPathRemove {
path, path,
@ -172,6 +173,7 @@ pub async fn worker(
for path in to_watch { for path in to_watch {
trace!(?path, "adding path to the watcher"); trace!(?path, "adding path to the watcher");
if let Err(err) = w.watch(&path, notify::RecursiveMode::Recursive) { if let Err(err) = w.watch(&path, notify::RecursiveMode::Recursive) {
error!(?err, "notify watch() error");
errors errors
.send(RuntimeError::FsWatcherPathAdd { .send(RuntimeError::FsWatcherPathAdd {
path, path,
@ -179,6 +181,7 @@ pub async fn worker(
err, err,
}) })
.await?; .await?;
// TODO: unwatch and re-watch manually while ignoring all the erroring paths
} else { } else {
pathset.insert(path); pathset.insert(path);
} }