Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Should not catch exception that threw by callback #99

Merged
merged 1 commit into from

2 participants

@JacksonTian

When exception threw by callback, the callback will be executed twice.

@tj tj merged commit 9ce8997 into tj:master
@JacksonTian JacksonTian deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2013
  1. @JacksonTian
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 3 deletions.
  1. +4 −3 lib/ejs.js
  2. +19 −0 test/ejs.js
View
7 lib/ejs.js
@@ -305,15 +305,16 @@ exports.renderFile = function(path, options, fn){
options.filename = path;
+ var str;
try {
- var str = options.cache
+ str = options.cache
? cache[key] || (cache[key] = read(path, 'utf8'))
: read(path, 'utf8');
-
- fn(null, exports.render(str, options));
} catch (err) {
fn(err);
+ return;
}
+ fn(null, exports.render(str, options));
};
/**
View
19 test/ejs.js
@@ -107,6 +107,25 @@ describe('ejs.renderFile(path, options, fn)', function(){
done();
});
})
+
+ it('should not catch err threw by callback', function(done){
+ var options = { name: 'tj', open: '{', close: '}' };
+ var counter = 0;
+ try {
+ ejs.renderFile('test/fixtures/user.ejs', options, function(err, html){
+ counter++;
+ if (err) {
+ err.message.should.not.equal('Exception in callback');
+ return done(err);
+ }
+ throw new Error('Exception in callback');
+ });
+ } catch (err) {
+ counter.should.equal(1);
+ err.message.should.equal('Exception in callback');
+ done();
+ }
+ })
})
describe('<%=', function(){
Something went wrong with that request. Please try again.