From 8d97f81880002ff3d8893869ce52e8684287a233 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 7 Mar 2017 21:14:57 +0100 Subject: Panic with better message if template not found (fixes #4) --- askama_derive/src/path.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'askama_derive/src/path.rs') diff --git a/askama_derive/src/path.rs b/askama_derive/src/path.rs index 96ed8c1..aac6557 100644 --- a/askama_derive/src/path.rs +++ b/askama_derive/src/path.rs @@ -12,7 +12,14 @@ fn template_dir() -> PathBuf { pub fn get_template_source(tpl_file: &str) -> String { let mut path = template_dir(); path.push(Path::new(tpl_file)); - let mut f = File::open(path).unwrap(); + let mut f = match File::open(&path) { + Err(_) => { + let msg = format!("unable to open template file '{}'", + &path.to_str().unwrap()); + panic!(msg); + }, + Ok(f) => f, + }; let mut s = String::new(); f.read_to_string(&mut s).unwrap(); s -- cgit