mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.54k stars 638 forks source link

Enrich errors with information about issues happening inside the filters #1287

Open derberg opened 4 years ago

derberg commented 4 years ago

Context

Debugging such errors is a challenge. Luckily you have a hidden config feature (I mean hidden as not documented) that you enable like this dev: true that improves debugging of filters but then again debugging of templates gets worse. Example of errors of the same errors I caused above:

I have this sandbox project where I play with Nunjucks functionality. I used it to quickly generate the above errors.

Questions

First of all, do you know why it is happening like this? any ideas already on how to improve. Of course, the best would be to combine both awesome examples from above, but I have a feeling that it might not be possible and this is why you added the dev flag. This is the only way I explain to myself why it is done now like this. Thoughts?

I know I can explicitly add try-catch to my filter to get errors related to custom filters without a dev flag to also keep good errors for templates, but doing it with each filter seems cumbersome. Any opinions would be appreciated.

ogonkov commented 4 years ago

Looks like dev flag is false by default for purpose

https://github.com/mozilla/nunjucks/blob/2031bf2b1e28a0d477cefb263e36943176f946f7/nunjucks/src/environment.js#L42-L47