diff --git a/salt/template.py b/salt/template.py index a33449809d..f6f2ab7ec7 100644 --- a/salt/template.py +++ b/salt/template.py @@ -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 diff --git a/salt/utils/templates.py b/salt/utils/templates.py index fb390dc699..5caec361cd 100644 --- a/salt/utils/templates.py +++ b/salt/utils/templates.py @@ -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,