Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve jinja2 templating error report for TemplateError #783

Merged
merged 1 commit into from
Oct 30, 2021

Conversation

dverbeir
Copy link
Contributor

@dverbeir dverbeir commented Sep 2, 2021

jinja2.TemplateError does not include the template line number which can be of great help when troubleshooting errors like
'foo' has no attribute 'bar'

The line number can however be inferred from the stack trace. This was inspired by
https://github.com/saltstack/salt/blob/master/salt/utils/templates.py

Example output:

Jsonnet error: failed to compile test/main.jsonnet:
RUNTIME ERROR: Jsonnet jinja2 failed to render templates/abc.j2: Jinja2 TemplateError: 'foo' has no attribute 'bar', at templates/abc.j2:240

jinja2.TemplateError does not include the template line number
which can be of great help when troubleshooting errors like
   'foo' has no attribute 'bar'

The line number can however be inferred from the stack trace.
This was inspired by
https://github.com/saltstack/salt/blob/master/salt/utils/templates.py

Example output:

   Jsonnet error: failed to compile test/main.jsonnet:
    RUNTIME ERROR: Jsonnet jinja2 failed to render templates/abc.j2:
     Jinja2 TemplateError: 'foo' has no attribute 'bar', at templates/abc.j2:240

Signed-off-by: David Verbeiren <david.verbeiren@tessares.net>
@ramaro ramaro merged commit b4f08a5 into kapicorp:master Oct 30, 2021
@ramaro
Copy link
Member

ramaro commented Oct 30, 2021

Thank you @dverbeir !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants