From 20bbbd2f591cc742d3f5ec1a0f6246a2a5df1093 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 18 Jun 2020 21:29:24 -0600 Subject: [PATCH 1/3] Nicer handling of config file errors at startup --- core/bbs.js | 13 +++++++++++-- core/config.js | 3 +-- core/config_loader.js | 3 +++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/bbs.js b/core/bbs.js index 074a742b..87289e94 100644 --- a/core/bbs.js +++ b/core/bbs.js @@ -54,6 +54,8 @@ function printVersionAndExit() { } function main() { + let errorDisplayed = false; + async.waterfall( [ function processArgs(callback) { @@ -87,7 +89,14 @@ function main() { configPathSupplied = null; // make non-fatal; we'll go with defaults } } else { - console.error(err.message); + errorDisplayed = true; + console.error(`Configuration error: ${err.message}`); // eslint-disable-line no-console + if (err.hint) { + console.error(`Hint: ${err.hint}`); + } + if (err.configPath) { + console.error(`Note: ${err.configPath}`); + } } } return callback(err); @@ -114,7 +123,7 @@ function main() { }); } - if(err) { + if(err && !errorDisplayed) { console.error('Error initializing: ' + util.inspect(err)); } } diff --git a/core/config.js b/core/config.js index 791845b8..8c77de0c 100644 --- a/core/config.js +++ b/core/config.js @@ -48,7 +48,6 @@ exports.Config = class Config extends ConfigLoader { systemConfigInstance = new Config(options); systemConfigInstance.init(baseConfigPath, err => { if (err) { - console.stdout(`Configuration ${baseConfigPath} error: ${err.message}`); // eslint-disable-line no-console return cb(err); } @@ -56,7 +55,7 @@ exports.Config = class Config extends ConfigLoader { // instance we just created exports.get = systemConfigInstance.get.bind(systemConfigInstance); - return cb(err); + return cb(null); }); } diff --git a/core/config_loader.js b/core/config_loader.js index 768cbe1d..da3de0d9 100644 --- a/core/config_loader.js +++ b/core/config_loader.js @@ -180,6 +180,9 @@ module.exports = class ConfigLoader { }; ConfigCache.getConfigWithOptions(options, (err, config) => { + if (err) { + err.configPath = options.filePath; + } return cb(err, config); }); } From 8c1ff7e2283620a8dfa4524d8da5cb36da6cb05e Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 5 Jul 2020 15:32:10 -0600 Subject: [PATCH 2/3] Exit on error --- core/bbs.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/bbs.js b/core/bbs.js index 87289e94..e3d08ed4 100644 --- a/core/bbs.js +++ b/core/bbs.js @@ -125,6 +125,7 @@ function main() { if(err && !errorDisplayed) { console.error('Error initializing: ' + util.inspect(err)); + return process.exit(); } } ); From c565b8caecbcb3039517d932c17caea3cf34878a Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Tue, 7 Jul 2020 19:41:17 -0600 Subject: [PATCH 3/3] Handle missing section --- core/theme.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/theme.js b/core/theme.js index f763614d..c64792d5 100644 --- a/core/theme.js +++ b/core/theme.js @@ -265,6 +265,10 @@ exports.ThemeManager = class ThemeManager { }; [ 'menus', 'prompts'].forEach(sectionName => { + if (!_.isObject(mergedTheme.sectionName)) { + return Log.error({sectionName}, 'Merged theme is missing section'); + } + Object.keys(mergedTheme[sectionName]).forEach(entryName => { let createdFormSection = false; const mergedThemeMenu = mergedTheme[sectionName][entryName];