mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge pull request #5240 from basepi/jinjaerrors4966
Add line number to Jinja errors, Fix #4966
This commit is contained in:
commit
bc7088747a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user