config: add more error handling

This commit is contained in:
Guillermo Rauch 2016-07-07 07:50:18 -07:00
parent 4e6fc051ec
commit 2a6ec3e955

View file

@ -17,9 +17,12 @@ function watch () {
function exec (str) { function exec (str) {
const script = new vm.Script(str); const script = new vm.Script(str);
const mod = {}; const module = {};
script.runInNewContext(mod); script.runInNewContext({ module });
const cfg = mod.exports.config; const cfg = module.exports.config;
if (!module.exports) {
throw new Error('Error reading configuration: `module.exports` not set');
}
if (!cfg) { if (!cfg) {
throw new Error('Error reading configuration: `config` key is missing'); throw new Error('Error reading configuration: `config` key is missing');
} }