Skip to content

Commit

Permalink
Fix bug where exceptions were silently swallowed with synchronous render
Browse files Browse the repository at this point in the history
fixes #678, #1116, #1127, and #1164. Closes #689
  • Loading branch information
fdintino committed Jan 7, 2019
1 parent 04619ac commit bb59ec3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions 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)
-------------------

Expand Down
6 changes: 5 additions & 1 deletion nunjucks/src/environment.js
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/compiler.js
Expand Up @@ -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"] %}',
Expand Down

0 comments on commit bb59ec3

Please sign in to comment.