Refuse to start on invalid config

This commit is contained in:
Calvin Montgomery 2020-12-02 18:09:49 -08:00
parent d678fa56d1
commit 9e3c23c58a
3 changed files with 23 additions and 18 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.74.0",
"version": "3.74.1",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -136,29 +136,19 @@ let captchaConfig = new CaptchaConfig();
* Initializes the configuration from the given YAML file
*/
exports.load = function (file) {
let absPath = path.join(__dirname, "..", file);
try {
cfg = YAML.load(path.join(__dirname, "..", file));
cfg = YAML.load(absPath);
} catch (e) {
if (e.code === "ENOENT") {
LOGGER.info(file + " does not exist, assuming default configuration");
cfg = defaults;
return;
throw new Error(`No such file: ${absPath}`);
} else {
LOGGER.error("Error loading config file " + file + ": ");
LOGGER.error(e);
if (e.stack) {
LOGGER.error(e.stack);
}
cfg = defaults;
return;
throw new Error(`Invalid config file ${absPath}: ${e}`);
}
}
if (cfg == null) {
LOGGER.info(file + " is an Invalid configuration file, " +
"assuming default configuration");
cfg = defaults;
return;
throw new Error("Configuration parser returned null");
}
if (cfg.mail) {

View File

@ -5,7 +5,15 @@ require('source-map-support').install();
const LOGGER = require('@calzoneman/jsli')('main');
Config.load('config.yaml');
try {
Config.load('config.yaml');
} catch (e) {
LOGGER.fatal(
"Failed to load configuration: %s",
e
);
process.exit(1);
}
const sv = require('./server').init();
@ -26,7 +34,14 @@ if (!Config.get('debug')) {
function handleLine(line) {
if (line === '/reload') {
LOGGER.info('Reloading config');
Config.load('config.yaml');
try {
Config.load('config.yaml');
} catch (e) {
LOGGER.error(
"Failed to load configuration: %s",
e
);
}
require('./web/pug').clearCache();
} else if (line.indexOf('/switch') === 0) {
const args = line.split(' ');