Handle notify errors

This commit is contained in:
mo8it 2024-04-09 21:46:55 +02:00
parent b15e0a279b
commit 4110ae21af

View file

@ -1,6 +1,8 @@
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use notify_debouncer_mini::{ use notify_debouncer_mini::{
new_debouncer, notify::RecursiveMode, DebounceEventResult, DebouncedEventKind, new_debouncer,
notify::{self, RecursiveMode},
DebounceEventResult, DebouncedEventKind,
}; };
use std::{ use std::{
io::{self, BufRead, Write}, io::{self, BufRead, Write},
@ -26,6 +28,7 @@ enum InputEvent {
enum WatchEvent { enum WatchEvent {
Input(InputEvent), Input(InputEvent),
FileChange { exercise_ind: usize }, FileChange { exercise_ind: usize },
NotifyErr(notify::Error),
TerminalResize, TerminalResize,
} }
@ -36,11 +39,8 @@ struct DebouceEventHandler {
impl notify_debouncer_mini::DebounceEventHandler for DebouceEventHandler { impl notify_debouncer_mini::DebounceEventHandler for DebouceEventHandler {
fn handle_event(&mut self, event: DebounceEventResult) { fn handle_event(&mut self, event: DebounceEventResult) {
let Ok(event) = event else { let event = match event {
// TODO Ok(event) => {
return;
};
let Some(exercise_ind) = event let Some(exercise_ind) = event
.iter() .iter()
.filter_map(|event| { .filter_map(|event| {
@ -59,7 +59,12 @@ impl notify_debouncer_mini::DebounceEventHandler for DebouceEventHandler {
return; return;
}; };
self.tx.send(WatchEvent::FileChange { exercise_ind }); WatchEvent::FileChange { exercise_ind }
}
Err(e) => WatchEvent::NotifyErr(e),
};
let _ = self.tx.send(event);
} }
} }
@ -125,6 +130,7 @@ pub fn watch(state_file: &StateFile, exercises: &'static [Exercise]) -> Result<(
watch_state.run_exercise_with_ind(exercise_ind)?; watch_state.run_exercise_with_ind(exercise_ind)?;
watch_state.render()?; watch_state.render()?;
} }
WatchEvent::NotifyErr(e) => return Err(e.into()),
} }
} }