From 3ad43c07e82c8dcc4e00a39761717669628ee1b4 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Fri, 20 Nov 2015 23:46:48 -0700 Subject: [PATCH] * New user / apply crashes if no message areas defined #19 --- core/bbs.js | 12 +++++++++++- core/config.js | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/core/bbs.js b/core/bbs.js index e2bf8c4a..9b3e699d 100644 --- a/core/bbs.js +++ b/core/bbs.js @@ -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) { diff --git a/core/config.js b/core/config.js index d62e3eb0..2fe4cc30 100644 --- a/core/config.js +++ b/core/config.js @@ -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); } ],