Log errors on more instance failures conditions

Log errors messages to the log when setting up an instance fails in the
preparation phase, creating save phase, starting up phase, and so on.
Previously these were only sent back as a an error response to the
request that iniatied the wakeup of the instance.
This commit is contained in:
Hornwitser committed 2023-12-03 19:59:14 +01:00
1 parent 1095d2466d
commit 448cfbbb51
1 file changed
+19 -8
+19 -8
View File
@@ -634,6 +634,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
* Windows hard links are used instead due to symlinks being privileged. * Windows hard links are used instead due to symlinks being privileged.
*/ */
async syncMods() { async syncMods() {
this.logger.info("Syncing mods");
const modPackId = this.config.get("factorio.mod_pack"); const modPackId = this.config.get("factorio.mod_pack");
let modPack; let modPack;
if (modPackId === null) { if (modPackId === null) {
@@ -994,7 +995,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
try { try {
await this.prepare(); await this.prepare();
saveName = await this.prepareSave(saveName); saveName = await this.prepareSave(saveName);
} catch (err) { } catch (err: any) {
this.logger.error(`Error preparing instance: ${err.message}`);
this.notifyExit(); this.notifyExit();
await this.sendSaveListUpdate(); await this.sendSaveListUpdate();
throw err; throw err;
@@ -1002,7 +1004,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
try { try {
await this.start(saveName); await this.start(saveName);
} catch (err) { } catch (err: any) {
this.logger.error(`Error starting ${saveName}: ${err.message}`);
await this.stop(); await this.stop();
throw err; throw err;
} }
@@ -1016,7 +1019,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
try { try {
await this.prepare(); await this.prepare();
} catch (err) { } catch (err: any) {
this.logger.error(`Error preparing instance: ${err.message}`);
this.notifyExit(); this.notifyExit();
await this.sendSaveListUpdate(); await this.sendSaveListUpdate();
throw err; throw err;
@@ -1025,7 +1029,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
let { scenario, seed, mapGenSettings, mapSettings } = request; let { scenario, seed, mapGenSettings, mapSettings } = request;
try { try {
await this.startScenario(scenario, seed, mapGenSettings, mapSettings); await this.startScenario(scenario, seed, mapGenSettings, mapSettings);
} catch (err) { } catch (err: any) {
this.logger.error(`Error starting scenario ${scenario}: ${err.message}`);
await this.stop(); await this.stop();
throw err; throw err;
} }
@@ -1040,11 +1045,10 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
try { try {
this.logger.verbose("Writing server-settings.json"); this.logger.verbose("Writing server-settings.json");
await this.writeServerSettings(); await this.writeServerSettings();
this.logger.verbose("Creating save .....");
await this.syncMods(); await this.syncMods();
} catch (err) { } catch (err: any) {
this.logger.error(`Error preparing instance: ${err.message}`);
this.notifyExit(); this.notifyExit();
await this.sendSaveListUpdate(); await this.sendSaveListUpdate();
throw err; throw err;
@@ -1052,7 +1056,14 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
this.server.on("exit", () => this.notifyExit()); this.server.on("exit", () => this.notifyExit());
let { name, seed, mapGenSettings, mapSettings } = request; let { name, seed, mapGenSettings, mapSettings } = request;
await this.server.create(name, seed, mapGenSettings, mapSettings);
try {
this.logger.info("Creating save");
await this.server.create(name, seed, mapGenSettings, mapSettings);
} catch (err: any) {
this.logger.error(`Error creating save ${name}: ${err.message}`);
throw err;
}
await this.sendSaveListUpdate(); await this.sendSaveListUpdate();
this.logger.info("Successfully created save"); this.logger.info("Successfully created save");
} }