Merge pull request #5240 from basepi/jinjaerrors4966

Add line number to Jinja errors, Fix #4966
This commit is contained in:
David Boucha 2013-05-23 15:40:13 -07:00
commit bc7088747a

View File

@ -11,6 +11,7 @@ import imp
import logging
import tempfile
import traceback
import sys
# Import third party libs
import jinja2
@ -101,11 +102,15 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
jinja_env = jinja2.Environment(**env_args)
else:
jinja_env = jinja2.Environment(
undefined=jinja2.StrictUndefined,**env_args)
undefined=jinja2.StrictUndefined, **env_args)
try:
output = jinja_env.from_string(tmplstr).render(**context)
except jinja2.exceptions.TemplateSyntaxError as exc:
raise SaltTemplateRenderError(str(exc))
error = '{0}; line {1} in template'.format(
exc,
traceback.extract_tb(sys.exc_info()[2])[-1][1]
)
raise SaltTemplateRenderError(error)
# Workaround a bug in Jinja that removes the final newline
# (https://github.com/mitsuhiko/jinja2/issues/75)