diff --git a/src/Mjolnir.ts b/src/Mjolnir.ts index d27292c..3c1c098 100644 --- a/src/Mjolnir.ts +++ b/src/Mjolnir.ts @@ -320,11 +320,12 @@ export class Mjolnir { try { LogService.error("Mjolnir", "Error during startup:"); LogService.error("Mjolnir", extractRequestError(err)); + this.stop(); await this.logMessage(LogLevel.ERROR, "Mjolnir@startup", "Startup failed due to error - see console"); + throw err; } catch (e) { - // If we failed to handle the error, just crash - console.error(e); - process.exit(1); + LogService.error("Mjolnir", `Failed to report startup error to the management room: ${e}`); + throw err; } } } diff --git a/src/index.ts b/src/index.ts index e6896a0..0ed071f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,9 +57,14 @@ if (config.health.healthz.enabled) { config.RUNTIME.client = client; bot = await Mjolnir.setupMjolnirFromConfig(client); + } catch (err) { + console.error(`Failed to setup mjolnir from the config ${config.dataPath}: ${err}`); + throw err; + } + try { await bot.start(); } catch (err) { - bot?.logMessage(LogLevel.ERROR, "index", err); - process.exit(1); + console.error(`Mjolnir failed to start: ${err}`); + throw err; } })();