As stated in topic #1127, there are still problems with exceptions not being thrown in certain cases. I found out that if some problem happens with import errors inside included templates, Nunjucks will fail to generate the required exceptions. For example, create a template included.njk:
{% import 'unknown.njk' as nothing %}
String is {{ str | whatever }}
and the following script:
const path = 'C:/users/etc/thispath';
const nunjucks = require("nunjucks");
nunjucks.configure(path);
console.log(nunjucks.renderString("{% include 'included.njk' %}", { str: 'okay' }));
Nunjucks silently outputs a null string. Some notes:
import is removed from the njk file.I hope this is clear. Thanks in advance!
(bump)
Any news? TIA
Hi again,
Any prospects on this problem?
This is quite the issue would be interested in some guidance.
Thanks for your attention. A minimal test case would be as follows.
const nunjucks = require('nunjucks');
console.log(nunjucks.renderString('{% include "included.njk" %}', { str: 'okay' }));
String is {{ str }}
Run the script test.js. You will get 'String is okay' as expected.
Now, edit _included.njk_ so as to import a nonexistent file:
{% import 'unknown.njk' as dummy %}
String is {{ str }}
test.js again. You will get 'null' as the result. I'd expect an exception instead, saying that _unknown.njk_ was not found or a similar error.I hope it's clearer now!
Oh my bad! I'm experiencing the same error! Sorry for that confusion, was hoping someone could help me (us) figure that out.
I'm looking into this
Appreciate it! Will test.
Most helpful comment
Hi again,
Any prospects on this problem?