commit e0973d95f1b53d8d4bc64770668d81e7311876bc
parent f6325798b1a6d465f4c8ae8784555390e7973c7e
Author: Sergio Benitez <sb@sergio.bz>
Date: Tue, 23 Oct 2018 23:57:40 -0700
Log I/O error when live template reloading fails.
Diffstat:
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/contrib/lib/src/templates/fairing.rs b/contrib/lib/src/templates/fairing.rs
@@ -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 {
diff --git a/contrib/lib/tests/templates.rs b/contrib/lib/tests/templates.rs
@@ -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;
}