Skip to content

Commit 68ba15c

Browse files
committedJan 7, 2019
Fix bug where exceptions were silently swallowed with synchronous render
fixes #678, #1116, #1127, and #1164. Closes #689
1 parent 7c187ac commit 68ba15c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
 

‎CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
3.1.6 (unreleased)
5+
------------------
6+
7+
* Fix bug where exceptions were silently swallowed with synchronous render.
8+
Fixes [#678](https://github.com/mozilla/nunjucks/issues/678),
9+
[#1116](https://github.com/mozilla/nunjucks/issues/1116),
10+
[#1127](https://github.com/mozilla/nunjucks/issues/1127), and
11+
[#1164](https://github.com/mozilla/nunjucks/issues/1164)
12+
413
3.1.5 (Dec 13 2018)
514
-------------------
615

‎nunjucks/src/environment.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,11 @@ class Template extends Obj {
468468
this.rootRenderFunc(this.env, context, frame, globalRuntime, (err, res) => {
469469
if (didError) {
470470
// prevent multiple calls to cb
471-
return;
471+
if (cb) {
472+
return;
473+
} else {
474+
throw err;
475+
}
472476
}
473477
if (err) {
474478
err = lib._prettifyError(this.path, this.env.opts.dev, err);

‎tests/compiler.js

+8
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,14 @@
795795
});
796796

797797
if (!isSlim) {
798+
it('should throw exceptions when called synchronously', function() {
799+
var tmpl = new Template('{% from "doesnotexist" import foo %}');
800+
function templateRender() {
801+
tmpl.render();
802+
}
803+
expect(templateRender).to.throwException(/template not found: doesnotexist/);
804+
});
805+
798806
it('should include error line in raised TemplateError', function(done) {
799807
var tmplStr = [
800808
'{% set items = ["a", "b",, "c"] %}',

0 commit comments

Comments
 (0)
Please sign in to comment.