Repository: alacritty/alacritty
File: alacritty/src/config/monitor.rs (Rust)

Code before:
    };

    thread::spawn_named("config watcher", move || {
        // Get all unique parent directories.
        let mut parents = paths
            .iter()
            .map(|path| {
                let mut path = path.clone();
                path.pop();
                path
            })
            .collect::<Vec<PathBuf>>();
        parents.sort_unstable();
        parents.dedup();

        let watcher = debouncer.watcher();
        // Watch all configuration file directories.
        for parent in &parents {
            if let Err(err) = watcher.watch(parent, RecursiveMode::NonRecursive) {
                debug!("Unable to watch config directory {:?}: {}", parent, err);
            }
        }

        loop {
            let res = match rx.recv() {
                Ok(res) => res,
                Err(err) => {
                    debug!("Config watcher channel dropped unexpectedly: {}", err);
                    break;
                },
            };

            if let Ok(events) = res {
                if events.iter().any(|e| paths.contains(&e.path)) {
                    // Always reload the primary configuration file.
                    let event = Event::new(EventType::ConfigReload(paths[0].clone()), None);
                    let _ = event_proxy.send_event(event);
                }
            }
        }
    });
}


Review comment (bug):
Let's just also log the error for `res` here and be done with it. Wasted too much time already on this dependency bump.

So both `Err(err)` and `Err(Err(err))` should print debug logs, just to make sure we're not ignoring serious issues.

Probably easiest to use one error message for both, no need to be that specific in a debug message unseen by most anyway.

Code after:
    };

    thread::spawn_named("config watcher", move || {
        // Get all unique parent directories.
        let mut parents = paths
            .iter()
            .map(|path| {
                let mut path = path.clone();
                path.pop();
                path
            })
            .collect::<Vec<PathBuf>>();
        parents.sort_unstable();
        parents.dedup();

        let watcher = debouncer.watcher();
        // Watch all configuration file directories.
        for parent in &parents {
            if let Err(err) = watcher.watch(parent, RecursiveMode::NonRecursive) {
                debug!("Unable to watch config directory {:?}: {}", parent, err);
            }
        }

        loop {
            let events = match rx.recv() {
                Ok(Ok(events)) => events,
                Ok(Err(err)) => {
                    debug!("Config watcher errors: {:?}", err);
                    continue;
                },
                Err(err) => {
                    debug!("Config watcher channel dropped unexpectedly: {}", err);
                    break;
                },
            };

            if events.iter().any(|e| paths.contains(&e.path)) {
                // Always reload the primary configuration file.
                let event = Event::new(EventType::ConfigReload(paths[0].clone()), None);
                let _ = event_proxy.send_event(event);
            }
        }
    });
}