Print a warning on invalid keys in config

This commit is contained in:
Pavel Djundik 2019-03-04 20:35:21 +02:00
parent 2e0100d31c
commit 7c1efb18d1
2 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,5 @@
"use strict"; "use strict";
const _ = require("lodash");
const log = require("../log"); const log = require("../log");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
@ -34,7 +33,7 @@ if (process.getuid) {
Utils.checkOldHome(); Utils.checkOldHome();
// Merge config key-values passed as CLI options into the main config // Merge config key-values passed as CLI options into the main config
_.merge(Helper.config, program.config); Helper.mergeConfig(Helper.config, program.config);
require("./start"); require("./start");

View File

@ -230,7 +230,11 @@ function getDefaultNick() {
} }
function mergeConfig(oldConfig, newConfig) { function mergeConfig(oldConfig, newConfig) {
return _.mergeWith(oldConfig, newConfig, (objValue, srcValue, key) => { return _.mergeWith(oldConfig, newConfig, (objValue, srcValue, key, object) => {
if (!object.hasOwnProperty(key)) {
log.warn(`Unknown key "${colors.bold(key)}", please verify your config.`);
}
// Do not override config variables if the type is incorrect (e.g. object changed into a string) // Do not override config variables if the type is incorrect (e.g. object changed into a string)
if (typeof objValue !== "undefined" && objValue !== null && typeof objValue !== typeof srcValue) { if (typeof objValue !== "undefined" && objValue !== null && typeof objValue !== typeof srcValue) {
log.warn(`Incorrect type for "${colors.bold(key)}", please verify your config.`); log.warn(`Incorrect type for "${colors.bold(key)}", please verify your config.`);