server: Perform init after adding uncaught exception handler

This avoids an unnecessary `try` block.
pull/4656/head
Richard Hansen 2020-12-22 00:45:33 -05:00 committed by John McLear
parent 86ceb2b610
commit d339f2a671
1 changed files with 9 additions and 16 deletions

View File

@ -60,22 +60,6 @@ exports.start = async () => {
stats.gauge('memoryUsage', () => process.memoryUsage().rss);
stats.gauge('memoryUsageHeap', () => process.memoryUsage().heapUsed);
await util.promisify(npm.load)();
try {
await db.init();
await plugins.update();
console.info(`Installed plugins: ${plugins.formatPluginsWithVersion()}`);
console.debug(`Installed parts:\n${plugins.formatParts()}`);
console.debug(`Installed hooks:\n${plugins.formatHooks()}`);
await hooks.aCallAll('loadSettings', {settings});
await hooks.aCallAll('createServer');
} catch (e) {
console.error(`exception thrown: ${e.message}`);
if (e.stack) console.log(e.stack);
process.exit(1);
}
process.on('uncaughtException', exports.exit);
// As of v14, Node.js does not exit when there is an unhandled Promise rejection. Convert an
// unhandled rejection into an uncaught exception, which does cause Node.js to exit.
@ -105,6 +89,15 @@ exports.start = async () => {
// Pass undefined to exports.exit because this is not an abnormal termination.
process.on('SIGTERM', () => exports.exit());
await util.promisify(npm.load)();
await db.init();
await plugins.update();
console.info(`Installed plugins: ${plugins.formatPluginsWithVersion()}`);
console.debug(`Installed parts:\n${plugins.formatParts()}`);
console.debug(`Installed hooks:\n${plugins.formatHooks()}`);
await hooks.aCallAll('loadSettings', {settings});
await hooks.aCallAll('createServer');
// Return the HTTP server to make it easier to write tests.
return express.server;
};