Skip to content

Commit

Permalink
Always provide a error message when using undefiend jinja variables
Browse files Browse the repository at this point in the history
This stopped working with newer jinja versions.
  • Loading branch information
Gagi2k committed Jul 22, 2021
1 parent 25df11e commit 4f4027b
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions qface/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ def merge(a, b):
return a


def template_error_handler(traceback):
exc_type, exc_obj, exc_tb = traceback.exc_info
error = exc_obj
if isinstance(exc_type, TemplateError):
error = exc_obj.message
message = '{0}:{1}: error: {2}'.format(exc_tb.tb_frame.f_code.co_filename, exc_tb.tb_lineno, error)
click.secho(message, fg='red', err=True)


class TestableUndefined(StrictUndefined):
"""Return an error for all undefined values, but allow testing them in if statements"""
def __bool__(self):
Expand Down Expand Up @@ -91,7 +82,6 @@ def __init__(self, search_path, context={}, force=False):
trim_blocks=True,
lstrip_blocks=True,
)
self.env.exception_handler = template_error_handler
self.env.filters.update(get_filters())
self._destination = Path()
self._path = Path()
Expand Down Expand Up @@ -185,7 +175,11 @@ def write(self, file_path, template, context={}, preserve=False, force=False):
click.secho(message, fg='red', err=True)
error = True
except TemplateError as exc:
# Just return with an error, the generic template_error_handler takes care of printing it
exc_tb = sys.exc_info()[2]
while exc_tb.tb_next != None:
exc_tb = exc_tb.tb_next
message = '{0}:{1}: error: {2}'.format(exc_tb.tb_frame.f_code.co_filename, exc_tb.tb_lineno, exc.message)
click.secho(message, fg='red', err=True)
error = True

if error and Generator.strict:
Expand Down

0 comments on commit 4f4027b

Please sign in to comment.