From 7f2f270534251bfddbf25d9e1b90eddecf5e1ade Mon Sep 17 00:00:00 2001 From: Archangel Date: Fri, 31 Jan 2025 01:17:06 +0100 Subject: [PATCH] Wrap saving in try-catch so that if an error occurs the server will continue to save other profiles --- project/src/servers/SaveServer.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/project/src/servers/SaveServer.ts b/project/src/servers/SaveServer.ts index 1fa97c5d..cf00d015 100644 --- a/project/src/servers/SaveServer.ts +++ b/project/src/servers/SaveServer.ts @@ -72,12 +72,19 @@ export class SaveServer { */ public async save(): Promise { const timer = new Timer(); + let savedProfiles = 0; + for (const [sessionId] of this.profiles) { - await this.saveProfile(sessionId); + try { + await this.saveProfile(sessionId); + savedProfiles++; + } catch (error) { + this.logger.error(`Could not save profile ${sessionId} | ${error}`); + } } - const profileCount = this.profiles.size; + this.logger.debug( - `Saving ${profileCount} profile${profileCount > 1 ? "s" : ""} took ${timer.getTime("ms")}ms`, + `Saving ${savedProfiles} profile${savedProfiles > 1 ? "s" : ""} took ${timer.getTime("ms")}ms`, false, ); }