-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Exception Handling when using jinja2.DictLoader #2065
Comments
The value in the traceback is the name of a file, not the name of a template. There's no file backing templates for |
Is there no way to add the name of the template into the traceback else the user has no idea which one of their templates caused the error? |
If this isn’t the right way - is there currently any way that I can determine what template in the dictionary caused an exception when using a DictLoader? |
It looks like it is available in Update: It looks like it can't be relied upon, some Exceptions which fall under TemplateError populate these fields and some don't - I would have expected TemplateNotFound to set |
If I use the
jinja2.FileSystemLoader
and there is an error within my Jinja2 template then the Exception is raised and it reports the file that caused the issue, e.g:However, if I use
jinja2.DictLoader
then when it raises an Exception it reports the file as<unknown>
even though I am passing it the name of a template, e.g:The following code replicates the issue:
The full trackback is as follows:
As we are passing the name of the template into
get_template()
then it knows the name of the template - the same is true if it includes another template from the dict - is it possible to actually report the template name (instead of<unknown>
- maybe<actual template name>
) when using the DictLoader? When I include multiple templates it gets quite confusing to understand which template the error occurred in - the line numbers seem to be correct once I work out what template it is referring to.Environment:
The text was updated successfully, but these errors were encountered: