diff --git a/CHANGELOG.md b/CHANGELOG.md index 2318db8c..9c065bf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Changelog ========= +3.1.6 (unreleased) +------------------ + +* Fix bug where exceptions were silently swallowed with synchronous render. + Fixes [#678](https://github.com/mozilla/nunjucks/issues/678), + [#1116](https://github.com/mozilla/nunjucks/issues/1116), + [#1127](https://github.com/mozilla/nunjucks/issues/1127), and + [#1164](https://github.com/mozilla/nunjucks/issues/1164) + 3.1.5 (Dec 13 2018) ------------------- diff --git a/nunjucks/src/environment.js b/nunjucks/src/environment.js index e7fd163b..bb1c3b90 100644 --- a/nunjucks/src/environment.js +++ b/nunjucks/src/environment.js @@ -468,7 +468,11 @@ class Template extends Obj { this.rootRenderFunc(this.env, context, frame, globalRuntime, (err, res) => { if (didError) { // prevent multiple calls to cb - return; + if (cb) { + return; + } else { + throw err; + } } if (err) { err = lib._prettifyError(this.path, this.env.opts.dev, err); diff --git a/tests/compiler.js b/tests/compiler.js index d6b590d9..a282ecca 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -795,6 +795,14 @@ }); if (!isSlim) { + it('should throw exceptions when called synchronously', function() { + var tmpl = new Template('{% from "doesnotexist" import foo %}'); + function templateRender() { + tmpl.render(); + } + expect(templateRender).to.throwException(/template not found: doesnotexist/); + }); + it('should include error line in raised TemplateError', function(done) { var tmplStr = [ '{% set items = ["a", "b",, "c"] %}',