Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add try/catch

  • Loading branch information...
commit 5e272f45a178eb5b9102ca28a33088a903333308 1 parent a5dee85
@pvorb authored
Showing with 32 additions and 33 deletions.
  1. +32 −33 tpl.js
View
65 tpl.js
@@ -26,44 +26,43 @@ var defaultConf = {
function apply(file, cb) {
// look for configuration directory
confdir(process.cwd(), 'tpl', function(err, dir) {
- if (err) {
- cb(err);
- return;
- }
-
- // read configuration file
- var json = fs.readFileSync(path.resolve(dir, 'conf.json'), 'utf8');
- var conf = JSON.parse(json);
- // set configuration
- conf = append(defaultConf, conf);
+ try {
+ // read configuration file
+ var json = fs.readFileSync(path.resolve(dir, 'conf.json'), 'utf8');
+ var conf = JSON.parse(json);
+ // set configuration
+ conf = append(defaultConf, conf);
- var ext = path.extname(file);
- var parser;
- // determine parser
- if (typeof conf.parsers[ext] != 'undefined')
- parser = conf.parser[ext];
- else
- parser = conf.parsers.default;
- // require parser
- parser = require(path.resolve(dir, 'parsers', parser + '.js'));
+ var ext = path.extname(file);
+ var parser;
+ // determine parser
+ if (typeof conf.parsers[ext] != 'undefined')
+ parser = conf.parser[ext];
+ else
+ parser = conf.parsers.default;
+ // require parser
+ parser = require(path.resolve(dir, 'parsers', parser + '.js'));
- // parse file
- var doc = parser(file);
+ // parse file
+ var doc = parser(file);
- var tpl;
- // determine template and engine
- if (typeof doc.template != 'undefined')
- tpl = conf.templates[doc.template]
- else
- tpl = conf.templates.default;
+ var tpl;
+ // determine template and engine
+ if (typeof doc.template != 'undefined')
+ tpl = conf.templates[doc.template]
+ else
+ tpl = conf.templates.default;
- // resolve template file
- tpl.file = path.resolve(dir, 'templates', tpl.file);
- // require template engine
- tpl.engine = require(path.resolve(dir, 'templates', tpl.engine + '.js'));
+ // resolve template file
+ tpl.file = path.resolve(dir, 'templates', tpl.file);
+ // require template engine
+ tpl.engine = require(path.resolve(dir, 'templates', tpl.engine + '.js'));
- // render
- return cb(null, tpl.engine(tpl.file, doc));
+ // render
+ cb(null, tpl.engine(tpl.file, doc));
+ } catch (err) {
+ cb(err);
+ }
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.