Merge pull request #3100 from thelounge/xpaw/warn-unknown-config-keys

Print a warning for invalid keys in config file or cli arguments
This commit is contained in:
Pavel Djundik 2019-03-05 14:26:41 +02:00 committed by GitHub
commit b6c7f45298
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -1,6 +1,5 @@
"use strict";
const _ = require("lodash");
const log = require("../log");
const fs = require("fs");
const path = require("path");
@ -34,7 +33,7 @@ if (process.getuid) {
Utils.checkOldHome();
// 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");

View file

@ -230,7 +230,11 @@ function getDefaultNick() {
}
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)
if (typeof objValue !== "undefined" && objValue !== null && typeof objValue !== typeof srcValue) {
log.warn(`Incorrect type for "${colors.bold(key)}", please verify your config.`);