Skip to content
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

Fix synchronous render throw bug #1181

Merged
merged 2 commits into from Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion tests/core.js
Expand Up @@ -20,7 +20,7 @@

function rmdir(dirPath) {
fs.emptyDirSync(dirPath);
fs.rmdir(dirPath);
fs.rmdirSync(dirPath);
}

describe('nunjucks.configure', function() {
Expand Down