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",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.74.0",
|
||||
"version": "3.74.1",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -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) {
|
||||
|
|
15
src/main.js
15
src/main.js
|
@ -5,7 +5,15 @@ require('source-map-support').install();
|
|||
|
||||
const LOGGER = require('@calzoneman/jsli')('main');
|
||||
|
||||
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');
|
||||
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(' ');
|
||||
|
|
Loading…
Reference in New Issue