Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

renderFile may call callback twice if it throws an error #227

Closed
Acubed opened this Issue · 0 comments

2 participants

@Acubed

In exports.renderFile in lib/index.js, if the requested file is not cached, it will be rendered with the following code:

    fs.readFile(path, 'utf8', function(err, str){
      if (err) return fn(err);
      try {
        fn(null, exports.render(str, options));
      } catch (err) {
        fn(err);
      }
    });

This poses a problem because if the call to fn() creates an exception (or any error) it wil be caught by Jade and be called again in the catch block. Callbacks are of course only supposed to be called once, and Jade shouldn't be catching outside exceptions anyways.
The code should probably look something like this:

    fs.readFile(path, 'utf8', function(err, str){
      if (err) return fn(err);
      try {
        var result = exports.render(str, options);
      } catch (err) {
        return fn(err);
      }
      fn(null, result);
    });
@tj tj closed this in 29b6610
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.