-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors in included templates are thrown asynchronously #678
Errors in included templates are thrown asynchronously #678
Comments
Any chance you could rework that example into a failing test in the nunjucks test suite? That'd be the next step towards fixing this. |
Done! In trying to make a failing test, I also discovered that it doesn't happen with invalid macros, but I'm not sure why. I thought that calling Template.render with a callback was the issue, but I see that's done anytime there's an import or include, and in most cases it works fine (even when there's an error such as the invalid macro) because compile doesn't throw during one of the calls where there's a callback, so it doesn't get reported asynchronously. You can see the test here—let me know if you want me to issue a PR or anything else. |
Yeah, go ahead and make a PR with that failing test, and mention this ticket number in its description. That makes it more visible / easier to find, the next time I get a chance to spend some time working on nunjucks. (Obviously if you're able to figure out a fix in the meantime and add it to the PR, even better!) Thanks! |
Half an hour of debugging an express-app brought up two lines: https://github.com/mozilla/nunjucks/blob/1d94ee6/src/environment.js#L454 Hope this helps. |
Just ran into this on v3. A typo in tag inside an included file causes nunjucks to throw an async error that can't be caught in a normal try/catch block. A workaround seems to be calling |
Catched this error when using express and nunjucks. If included template has error nunjucks render method fires two times: 1. parent template 2. errored included template. And after 2 express rejects with "Error: Can't set headers after they are sent." Workaround for express to not reject:
But need a better solution for at least render error on target page, not only in console. |
As far as I can tell, this applies to any block error and possibly any error at all
I've attached a folder (nunjucks-repro.zip) with the reproduction for convenience, and here's the code in each file:
repro.js
included.html
I wasn't able to figure out exactly why this is happening, but it appears the flow goes into an asyncIter (despite nothing async being used anywhere) here, and then when it calls render again, it has passed a callback, causing this path to be taken, which erroneously reports the error asynchronously.
I hacked it in my fork by just throwing instead of ever calling callbackAsap, but that's clearly not the right way to fix it.
thanks!
The text was updated successfully, but these errors were encountered: