nunjucks: nunjucks do not throw error when syntax error or none existing filter

hi guys, I have two templates: layout.nj and home.nj. home.nj extends layout.nj.

in somewhere of layout.nj, I have some syntax error, such as

{% set tpl_now = Date.now() %}

or use a filter not defined

{{user.userId | raw | default("null") }}

when I run my node server, env.render DO NOT throw error, and just return null silently.

maybe it’s better to throw error in such cases, and so we can find out what is going wrong.

any advice is appreciated.

Thx in advance

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

I agree that the wording of the docs is vague. One would expect, with no callback provided, for an error to be thrown by render()

@ArmorDarks thx. But according to the docs,

Renders the template named name with the context hash. If callback is provided, it will be called when done with any possible error as the first argument and the result as the second. Otherwise, the result is returned from render and errors are thrown.

If I do not provide a callback, errors should be thrown.

You need to check error in a callback of env.render (first argument). If it exists, you must throw it on your own. See docs