mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
template debugging
* more formatting of errors * logging of steps * better handling of edge cases
This commit is contained in:
parent
0e935486de
commit
c65af6a8f5
@ -37,6 +37,10 @@ def compile_template(template,
|
||||
derived from the template.
|
||||
'''
|
||||
|
||||
# if any error occurs, we return an empty dictionary
|
||||
ret = {}
|
||||
|
||||
log.debug('compile template: {0}'.format(template))
|
||||
# We "map" env to the same as saltenv until Boron is out in order to follow the same deprecation path
|
||||
kwargs.setdefault('env', saltenv)
|
||||
salt.utils.warn_until(
|
||||
@ -48,13 +52,16 @@ def compile_template(template,
|
||||
|
||||
# Template was specified incorrectly
|
||||
if not isinstance(template, string_types):
|
||||
return {}
|
||||
log.error('Template was specified incorrectly: {0}'.format(template))
|
||||
return ret
|
||||
# Template does not exists
|
||||
if not os.path.isfile(template):
|
||||
return {}
|
||||
log.error('Template does not exists: {0}'.format(template))
|
||||
return ret
|
||||
# Template is an empty file
|
||||
if salt.utils.is_empty(template):
|
||||
return {}
|
||||
log.error('Template is an empty file: {0}'.format(template))
|
||||
return ret
|
||||
|
||||
# Get the list of render funcs in the render pipe line.
|
||||
render_pipe = template_shebang(template, renderers, default)
|
||||
@ -64,14 +71,16 @@ def compile_template(template,
|
||||
input_data = ifile.read()
|
||||
if not input_data.strip():
|
||||
# Template is nothing but whitespace
|
||||
return {}
|
||||
log.error('Template is nothing but whitespace: {0}'.format(template))
|
||||
return ret
|
||||
|
||||
input_data = string_io(input_data)
|
||||
for render, argline in render_pipe:
|
||||
try:
|
||||
input_data.seek(0)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exp:
|
||||
log.error('error: {0}:\n{1}'.format(exp))
|
||||
|
||||
render_kwargs = dict(renderers=renderers, tmplpath=template)
|
||||
render_kwargs.update(kwargs)
|
||||
if argline:
|
||||
@ -88,8 +97,8 @@ def compile_template(template,
|
||||
template,
|
||||
ret.read()))
|
||||
ret.seek(0)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exp:
|
||||
log.error('error: {0}'.format(exp))
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -104,6 +104,7 @@ def wrap_tmpl_func(render_str):
|
||||
output = os.linesep.join(output.splitlines())
|
||||
|
||||
except SaltRenderError as exc:
|
||||
log.error("Rendering exception occured :{0}".format(exc))
|
||||
#return dict(result=False, data=str(exc))
|
||||
raise
|
||||
except Exception:
|
||||
@ -290,6 +291,11 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
|
||||
template.globals.update(unicode_context)
|
||||
output = template.render(**unicode_context)
|
||||
except jinja2.exceptions.TemplateSyntaxError as exc:
|
||||
print exc
|
||||
print out
|
||||
print line
|
||||
print tmplstr
|
||||
|
||||
trace = traceback.extract_tb(sys.exc_info()[2])
|
||||
line, out = _get_jinja_error(trace, context=unicode_context)
|
||||
if not line:
|
||||
@ -325,6 +331,13 @@ def render_jinja_tmpl(tmplstr, context, tmplpath=None):
|
||||
tmplstr = ''
|
||||
else:
|
||||
tmplstr += '\n{0}'.format(tracestr)
|
||||
log.debug("Jinja Error")
|
||||
log.debug("Exception: {0}".format(exc))
|
||||
log.debug("Out: {0}".format(out))
|
||||
log.debug("Line: {0}".format(line))
|
||||
log.debug("TmplStr: {0}".format(tmplstr))
|
||||
log.debug("TraceStr: {0}".format(tracestr))
|
||||
|
||||
raise SaltRenderError('Jinja error: {0}{1}'.format(exc, out),
|
||||
line,
|
||||
tmplstr,
|
||||
|
Loading…
Reference in New Issue
Block a user