* New user / apply crashes if no message areas defined #19

This commit is contained in:
Bryan Ashby 2015-11-20 23:46:48 -07:00
parent 839ab8fc91
commit 3ad43c07e8
2 changed files with 43 additions and 13 deletions

View File

@ -47,9 +47,18 @@ function bbsMain() {
// If the user supplied a path and we can't read/parse it
// then it's a fatal error
//
if(err) {
if('ENOENT' === err.code) {
console.error('Configuration file does not exist: ' + configPath);
} else {
console.error(err.toString());
}
}
callback(err);
/*
if(configPathSupplied && err) {
if('ENOENT' === err.code) {
console.error('Configuration file does not existing: ' + configPath);
console.error('Configuration file does not exist: ' + configPath);
} else {
console.error('Failed parsing configuration: ' + configPath);
}
@ -57,6 +66,7 @@ function bbsMain() {
} else {
callback(null);
}
*/
});
},
function initSystem(callback) {

View File

@ -16,19 +16,22 @@ function init(configPath, cb) {
async.waterfall(
[
function loadUserConfig(callback) {
fs.readFile(configPath, { encoding : 'utf8' }, function configData(err, data) {
if(err) {
callback(null, { } );
} else {
try {
var configJson = hjson.parse(data);
callback(null, configJson);
} catch(e) {
callback(e);
if(_.isString(configPath)) {
fs.readFile(configPath, { encoding : 'utf8' }, function configData(err, data) {
if(err) {
callback(err);
} else {
try {
var configJson = hjson.parse(data);
callback(null, configJson);
} catch(e) {
callback(e);
}
}
}
});
});
} else {
callback(null, { } );
}
},
function mergeWithDefaultConfig(configJson, callback) {
var mergedConfig = _.merge(getDefaultConfig(), configJson, function mergeCustomizer(conf1, conf2) {
@ -39,6 +42,23 @@ function init(configPath, cb) {
}
});
callback(null, mergedConfig);
},
function validate(mergedConfig, callback) {
//
// Various sections must now exist in config
//
if(!_.has(mergedConfig, 'messages.areas.') ||
!_.isArray(mergedConfig.messages.areas) ||
0 == mergedConfig.messages.areas.length ||
!_.isString(mergedConfig.messages.areas[0].name))
{
var msgAreasErr = new Error('Please create at least one message area');
msgAreasErr.code = 'EBADCONFIG';
callback(msgAreasErr);
return;
}
callback(null, mergedConfig);
}
],