mirror of https://github.com/calzoneman/sync.git
Refuse to start on invalid config
This commit is contained in:
parent
d678fa56d1
commit
9e3c23c58a
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.74.0",
|
"version": "3.74.1",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -136,29 +136,19 @@ let captchaConfig = new CaptchaConfig();
|
||||||
* Initializes the configuration from the given YAML file
|
* Initializes the configuration from the given YAML file
|
||||||
*/
|
*/
|
||||||
exports.load = function (file) {
|
exports.load = function (file) {
|
||||||
|
let absPath = path.join(__dirname, "..", file);
|
||||||
try {
|
try {
|
||||||
cfg = YAML.load(path.join(__dirname, "..", file));
|
cfg = YAML.load(absPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === "ENOENT") {
|
if (e.code === "ENOENT") {
|
||||||
LOGGER.info(file + " does not exist, assuming default configuration");
|
throw new Error(`No such file: ${absPath}`);
|
||||||
cfg = defaults;
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("Error loading config file " + file + ": ");
|
throw new Error(`Invalid config file ${absPath}: ${e}`);
|
||||||
LOGGER.error(e);
|
|
||||||
if (e.stack) {
|
|
||||||
LOGGER.error(e.stack);
|
|
||||||
}
|
|
||||||
cfg = defaults;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg == null) {
|
if (cfg == null) {
|
||||||
LOGGER.info(file + " is an Invalid configuration file, " +
|
throw new Error("Configuration parser returned null");
|
||||||
"assuming default configuration");
|
|
||||||
cfg = defaults;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.mail) {
|
if (cfg.mail) {
|
||||||
|
|
19
src/main.js
19
src/main.js
|
@ -5,7 +5,15 @@ require('source-map-support').install();
|
||||||
|
|
||||||
const LOGGER = require('@calzoneman/jsli')('main');
|
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();
|
const sv = require('./server').init();
|
||||||
|
|
||||||
|
@ -26,7 +34,14 @@ if (!Config.get('debug')) {
|
||||||
function handleLine(line) {
|
function handleLine(line) {
|
||||||
if (line === '/reload') {
|
if (line === '/reload') {
|
||||||
LOGGER.info('Reloading config');
|
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();
|
require('./web/pug').clearCache();
|
||||||
} else if (line.indexOf('/switch') === 0) {
|
} else if (line.indexOf('/switch') === 0) {
|
||||||
const args = line.split(' ');
|
const args = line.split(' ');
|
||||||
|
|
Loading…
Reference in New Issue