Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Exceptions being swallowed after import errors in included templates #1272

Closed
leosdad opened this issue Mar 16, 2020 · 7 comments · Fixed by #1301 · May be fixed by BitcoinOutput/bsc-genesis-contractin#15
Closed

Exceptions being swallowed after import errors in included templates #1272

leosdad opened this issue Mar 16, 2020 · 7 comments · Fixed by #1301 · May be fixed by BitcoinOutput/bsc-genesis-contractin#15

Comments

@leosdad
Copy link

leosdad commented Mar 16, 2020

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:

  • The exception is captured correctly if the contents of the njk file are directly used as the template.
  • The exception is also captured if the line with import is removed from the njk file.

I hope this is clear. Thanks in advance!

@leosdad
Copy link
Author

leosdad commented Apr 3, 2020

(bump)

Any news? TIA

@leosdad
Copy link
Author

leosdad commented Jun 13, 2020

Hi again,

Any prospects on this problem?

@MH15
Copy link

MH15 commented Jul 17, 2020

This is quite the issue would be interested in some guidance.

@leosdad
Copy link
Author

leosdad commented Jul 17, 2020

Thanks for your attention. A minimal test case would be as follows.

  1. Create a file named test.js with:
const nunjucks = require('nunjucks');
console.log(nunjucks.renderString('{% include "included.njk" %}', { str: 'okay' }));
  1. Create a file named included.njk:
String is {{ str }}
  1. Run the script test.js. You will get 'String is okay' as expected.

  2. Now, edit included.njk so as to import a nonexistent file:

{% import 'unknown.njk' as dummy %}
String is {{ str }}
  1. Run 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!

@MH15
Copy link

MH15 commented Jul 17, 2020

Oh my bad! I'm experiencing the same error! Sorry for that confusion, was hoping someone could help me (us) figure that out.

@fdintino
Copy link
Collaborator

I'm looking into this

@MH15
Copy link

MH15 commented Jul 20, 2020

Appreciate it! Will test.

# for free to join this conversation on GitHub. Already have an account? # to comment