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

Crash on missing file #5

Closed
gilbert opened this issue Jan 6, 2015 · 1 comment
Closed

Crash on missing file #5

gilbert opened this issue Jan 6, 2015 · 1 comment

Comments

@gilbert
Copy link

gilbert commented Jan 6, 2015

The following code tries to render a file that does not exist:

ejs.renderFile(__dirname + '/app/index.html.ejs')

...but you can't discern that from the resulting error message:

./node_modules/ejs/lib/ejs.js:213
      var tmpl = data.toString().trim();
                      ^
TypeError: Cannot call method 'toString' of undefined
    at ./node_modules/ejs/lib/ejs.js:213:23
    at fs.js:207:20
    at Object.oncomplete (fs.js:107:15)

The problem lies in this library's code using data before it checks for err:

    read(path, function (err, data) {
      var tmpl = data.toString().trim();
      if (err) {
        return cb(err);
      }
      if (opts.cache) {
        templateCache[path] = tmpl;
      }
      handleTemplate(tmpl);
    });
mde added a commit that referenced this issue Jan 6, 2015
@mde
Copy link
Owner

mde commented Jan 6, 2015

Fix pushed to NPM in v2.0.8. Thanks for catching this!

@mde mde closed this as completed Jan 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants