Skip to content

Commit

Permalink
fixes #28, do not bail in module code and capture unhandled exception…
Browse files Browse the repository at this point in the history
…s in cli.js
  • Loading branch information
monken committed Sep 13, 2017
1 parent adf3897 commit cdcff3c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ include({
console.error('Validation failed:', err.message);
process.exit(1);
});
}).catch(function(err) {
console.error(err);
process.exit(1);
});
6 changes: 0 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ function include(base, scope, args) {
strictSSL: true,
}).get('body').call('toString');
}
if(body) body.catch(bail);
if (args.type === 'json') {
return body.then(function(res) { return yaml.safeLoad(res, { schema: yamlSchema }) }).catch(function(yamlErr) {
return body.then(jsmin).then(JSON.parse).catch(function(jsonErr) {
Expand Down Expand Up @@ -201,8 +200,3 @@ function JSONifyString(string) {
});
return lines;
}

function bail(err) {
console.error(err.toString());
process.exit(1);
}
8 changes: 7 additions & 1 deletion t/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ var include = require('../index'),
describe(category, function() {
tests[category].forEach(function(test) {
it(test.name || 'include', function(done) {
exec('node', ['bin/cli.js', test.template], function(err, out) {
exec('node', ['bin/cli.js', test.template], function(err, out, stderr) {
if(test.exitCode) {
assert.ok(stderr.match(new RegExp(test.errorMessage)));
assert.equal(test.exitCode, err.code);
return done();
}

var json = JSON.parse(out.toString());
delete json.Metadata;
assert.deepEqual(json, test.output);
Expand Down
3 changes: 3 additions & 0 deletions t/includes/yaml/malformed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!Sub
- "arn:aws:route53:::hostedzone/${ZoneId}/rrset"
- { ZoneId: !If [IsProd, "XYZ" "ZQW" ] }
5 changes: 5 additions & 0 deletions t/tests/cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@
}
}
}
}, {
"name": "malformed yaml",
"template": "t/includes/yaml/malformed.yml",
"exitCode": 1,
"errorMessage": "missed comma"
}]
}

0 comments on commit cdcff3c

Please sign in to comment.