From 68ba15c4ae9efee32cfcefd0ef9e1b1f9dc95e36 Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Sun, 6 Jan 2019 22:58:13 -0500 Subject: [PATCH] Fix bug where exceptions were silently swallowed with synchronous render fixes #678, #1116, #1127, and #1164. Closes #689 --- CHANGELOG.md | 9 +++++++++ nunjucks/src/environment.js | 6 +++++- tests/compiler.js | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) 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"] %}',