Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Added patch to call the callback passed into compileFile in the event of an error thrown in compile #340

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/swig.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,16 @@ exports.Swig = function (opts) {
cb(err);
return;
}
cb(err, self.compile(src, options));
var compiled;

try {
compiled = self.compile(src, options);
} catch (err2) {
cb(err2);
return;
}

cb(err, compiled);
});
return;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ describe('swig.compileFile', function () {
}));
});
});

it('can use callback with errors', function (done) {
var errorTest = __dirname + '/cases-error/extends-non-existent.test.html';
expect(swig.compileFile(errorTest, {}, function (err) {
expect(err.errno).to.equal(34);
done();
}));
});
});

describe('swig.renderFile', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/cases-error/extends-non-existent.test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'does-not-exist.html' %}