From d65d08b9378d23ba3fa5b66739f6c78de466fdb8 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 7 Mar 2017 21:07:01 +0100 Subject: Panic with better message if template attribute is not found (fixes #3) --- askama_derive/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'askama_derive') diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index 752978e..f823299 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -19,9 +19,16 @@ struct TemplateMeta { // in the parsed struct or enum. Will panic if it does not find the required // template path, or if the `print` key has an unexpected value. fn get_template_meta(ast: &syn::DeriveInput) -> TemplateMeta { + let attr = ast.attrs.iter().find(|a| a.name() == "template"); + if attr.is_none() { + let msg = format!("'template' attribute not found on struct '{}'", + ast.ident.as_ref()); + panic!(msg); + } + + let attr = attr.unwrap(); let mut path = None; let mut print = "none".to_string(); - let attr = ast.attrs.iter().find(|a| a.name() == "template").unwrap(); if let syn::MetaItem::List(_, ref inner) = attr.value { for nm_item in inner { if let syn::NestedMetaItem::MetaItem(ref item) = *nm_item { -- cgit