Log I/O error when live template reloading fails.

This commit is contained in:
Sergio Benitez 2018-10-23 23:57:40 -07:00
parent f6325798b1
commit e0973d95f1
2 changed files with 11 additions and 10 deletions

View File

@ -50,19 +50,19 @@ mod context {
impl ContextManager {
crate fn new(ctxt: Context) -> ContextManager {
let (tx, rx) = channel();
let watcher = raw_watcher(tx).and_then(|mut watcher| {
watcher.watch(ctxt.root.canonicalize()?, RecursiveMode::Recursive)?;
Ok(watcher)
});
let watcher = if let Ok(mut watcher) = raw_watcher(tx) {
if watcher.watch(ctxt.root.clone(), RecursiveMode::Recursive).is_ok() {
Some(Mutex::new((watcher, rx)))
} else {
warn!("Could not monitor the templates directory for changes.");
warn_!("Live template reload will be unavailable");
let watcher = match watcher {
Ok(watcher) => Some(Mutex::new((watcher, rx))),
Err(e) => {
warn!("Failed to enable live template reloading: {}", e);
debug_!("Reload error: {:?}", e);
warn_!("Live template reloading is unavailable.");
None
}
} else {
warn!("Could not instantiate a filesystem watcher.");
warn_!("Live template reload will be unavailable");
None
};
ContextManager {

View File

@ -157,6 +157,7 @@ mod templates_tests {
// if the new content is correct, we are done
let new_rendered = Template::show(client.rocket(), RELOAD_TEMPLATE, ());
if new_rendered == Some(NEW_TEXT.into()) {
write_file(&reload_path, INITIAL_TEXT);
return;
}