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.55k stars 638 forks source link

Errors thrown from custom filters don't include line/column information #975

Open callumlocke opened 7 years ago

callumlocke commented 7 years ago

If you make a custom filter, and it throws an error because of some bad input, the resulting error does not give you the location of the bad filter call within your template.

Is there some special way to get this info?

ArmorDarks commented 7 years ago

I don't know any official way.

I agree that it would be much better to have at least some kind of Error with stack.

What you can do right now is to wrap content of your filter into try...catch block, and in catch throw error with provided information about source. Unfortunately, you have to figure out your own way to define that information about source.

For example, we're using Gray Matter to collect meta information about pages, and we inject it as part of context, so we can access at least information about which exactly template thrown error like that.