From 448cfbbb5118b5cfc36b41dcc3e834d84a8fce82 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 3 Dec 2023 00:21:26 +0100 Subject: [PATCH] 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. --- packages/host/src/Instance.ts | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/host/src/Instance.ts b/packages/host/src/Instance.ts index 6be4638e..f68bdd24 100644 --- a/packages/host/src/Instance.ts +++ b/packages/host/src/Instance.ts @@ -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. */ async syncMods() { + this.logger.info("Syncing mods"); const modPackId = this.config.get("factorio.mod_pack"); let modPack; if (modPackId === null) { @@ -994,7 +995,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); try { await this.prepare(); saveName = await this.prepareSave(saveName); - } catch (err) { + } catch (err: any) { + this.logger.error(`Error preparing instance: ${err.message}`); this.notifyExit(); await this.sendSaveListUpdate(); throw err; @@ -1002,7 +1004,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); try { await this.start(saveName); - } catch (err) { + } catch (err: any) { + this.logger.error(`Error starting ${saveName}: ${err.message}`); await this.stop(); throw err; } @@ -1016,7 +1019,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); try { await this.prepare(); - } catch (err) { + } catch (err: any) { + this.logger.error(`Error preparing instance: ${err.message}`); this.notifyExit(); await this.sendSaveListUpdate(); throw err; @@ -1025,7 +1029,8 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); let { scenario, seed, mapGenSettings, mapSettings } = request; try { await this.startScenario(scenario, seed, mapGenSettings, mapSettings); - } catch (err) { + } catch (err: any) { + this.logger.error(`Error starting scenario ${scenario}: ${err.message}`); await this.stop(); throw err; } @@ -1040,11 +1045,10 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); try { this.logger.verbose("Writing server-settings.json"); await this.writeServerSettings(); - - this.logger.verbose("Creating save ....."); await this.syncMods(); - } catch (err) { + } catch (err: any) { + this.logger.error(`Error preparing instance: ${err.message}`); this.notifyExit(); await this.sendSaveListUpdate(); throw err; @@ -1052,7 +1056,14 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); this.server.on("exit", () => this.notifyExit()); 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(); this.logger.info("Successfully created save"); }