From 2fc71cc74e278aa244cbb81e07de19419f89e1ab Mon Sep 17 00:00:00 2001 From: Martin Gracik Date: Fri, 29 Oct 2010 14:41:23 +0200 Subject: [PATCH] Catch template exceptions --- src/pylorax/ltmpl.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index eeb20d67..1cde8912 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -19,10 +19,12 @@ # Red Hat Author(s): Martin Gracik # +import sys import shlex from mako.template import Template from mako.lookup import TemplateLookup +from mako.exceptions import RichTraceback class LoraxTemplate(object): @@ -32,7 +34,16 @@ class LoraxTemplate(object): # otherwise the file includes will not work properly lookup = TemplateLookup(directories=["/"]) template = Template(filename=template_file, lookup=lookup) - s = template.render(**variables) + + try: + s = template.render(**variables) + except: + traceback = RichTraceback() + for (filename, lineno, function, line) in traceback.traceback: + print "File %s, line %s, in %s" % (filename, lineno, function) + print line + + sys.exit(2) # split, strip and remove empty lines lines = s.splitlines()