-
Notifications
You must be signed in to change notification settings - Fork 94
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
jinja2: improve error context information #4842
jinja2: improve error context information #4842
Conversation
1105aa4
to
6f5b8e6
Compare
* When `{% include %}` statements are involved, the error context we extract highlights the include statement as the error *not* the actual line where the error happened. * This expands the context extraction to pull out the relevant lines from include files where this happens.
6f5b8e6
to
a5d6c03
Compare
@@ -80,7 +111,7 @@ def __init__(self, reason, index=None, line=None, lines=None, | |||
self.fpath = fpath | |||
self.help_lines = help_lines or [] | |||
|
|||
def __str__(self): | |||
def __str__(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obvious but mypy needs this to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested out. Before:
Jinja2Error: Jinja2 Error: some error
Context lines:
# line before include
{% include "foo.cylc" %} <-- Exception
After:
Jinja2Error: Jinja2 Error: some error
File ~/cylc-run/GAH/foo.cylc
# line before error
{{ raise('some error') }}
# line after error <-- Exception
File ~/cylc-run/GAH/flow.cylc
#!Jinja2
# line before include
{% include "foo.cylc" %} <-- Exception
Minor niggle is that the traceback is reversed compared to what you would expect i.e. foo.cylc
comes before flow.cylc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Just needs a change log entry?
Our Jinja2 error context reporting gets stuck on include statements.
A couple of our Cylc 8 trialers have hit Python 2->3 issues (e.g.
dict.keys()
) that have been obscured by this. I suspect a few more will run into similar issues. It's quite hard to debug these issues when all you see isTypeError
and the line the{% include
statement is on.Took a look, seems an easy fix.
Example
Should validate with Cylc 7 but fail with Cylc 8 due to Python the 2->3 change in
dict.keys
return type:(flow.cylc)
(foo.cylc)
Before this change only the
{% include
line would be highlighted, after this change the real error should also appear in the error.Requirements check-list
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
andconda-environment.yml
.