From fa55054a98d511dfd2344a13460d30e36fbe1a3d Mon Sep 17 00:00:00 2001 From: gereon77 Date: Wed, 26 Jul 2023 09:15:43 +0200 Subject: [PATCH] Introduce SnR error to log the game id --- agot-bg-game-server/src/common/EntireGame.ts | 9 +++++---- .../src/common/ingame-game-state/IngameGameState.ts | 11 ++++++----- .../src/common/ingame-game-state/Player.ts | 5 +++-- .../spymaster-game-state/SpymasterGameState.ts | 5 +++-- .../RodrikTheReaderAbilityGameState.ts | 3 ++- .../ingame-game-state/game-data-structure/Game.ts | 13 +++++++------ .../ingame-game-state/game-data-structure/Region.ts | 3 ++- .../ingame-game-state/port-helper/PortHelper.ts | 2 +- .../MoveLoyaltyTokensGameState.ts | 4 ++-- agot-bg-game-server/src/utils/snrError.ts | 8 ++++++++ 10 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 agot-bg-game-server/src/utils/snrError.ts diff --git a/agot-bg-game-server/src/common/EntireGame.ts b/agot-bg-game-server/src/common/EntireGame.ts index 69c757a41..a1dc361ac 100644 --- a/agot-bg-game-server/src/common/EntireGame.ts +++ b/agot-bg-game-server/src/common/EntireGame.ts @@ -24,6 +24,7 @@ import getElapsedSeconds from "../utils/getElapsedSeconds"; import WildlingCardType from "./ingame-game-state/game-data-structure/wildling-card/WildlingCardType"; import House from "./ingame-game-state/game-data-structure/House"; import { EntireGameSnapshot } from "./ingame-game-state/game-data-structure/Game"; +import SnrError from "../utils/snrError"; export enum NotificationType { READY_TO_START, @@ -105,7 +106,7 @@ export default class EntireGame extends GameState this.gameSettings.playerCount == gameSetup.playerCount); if (gameSetup == undefined) { - throw new Error(`Invalid playerCount ${this.gameSettings.playerCount} for setupId ${this.gameSettings.setupId}`); + throw new SnrError(this, `Invalid playerCount ${this.gameSettings.playerCount} for setupId ${this.gameSettings.setupId}`); } return gameSetup; @@ -180,7 +181,7 @@ export default class EntireGame extends GameState s.childGameState, serializedEntireGame as SerializedGameState); if (!serializedGameState) { - throw new Error(); + throw new SnrError(this); } return { @@ -438,12 +439,12 @@ export default class EntireGame extends GameState { if (!p.liveClockData) { - throw new Error("LiveClockData must be present in doPlayerClocksHandling"); + throw new SnrError(this, "LiveClockData must be present in doPlayerClocksHandling"); } if (p.liveClockData.timerStartedAt) { if (!p.liveClockData.serverTimer) { - throw new Error("serverTimer must be present in doPlayerClocksHandling"); + throw new SnrError(this, "serverTimer must be present in doPlayerClocksHandling"); } // Stop the timer diff --git a/agot-bg-game-server/src/common/ingame-game-state/IngameGameState.ts b/agot-bg-game-server/src/common/ingame-game-state/IngameGameState.ts index c7702331c..42b3fa3c7 100644 --- a/agot-bg-game-server/src/common/ingame-game-state/IngameGameState.ts +++ b/agot-bg-game-server/src/common/ingame-game-state/IngameGameState.ts @@ -45,6 +45,7 @@ import getElapsedSeconds from "../../utils/getElapsedSeconds"; import orders from "./game-data-structure/orders"; import { OrderOnMapProperties, UnitOnMapProperties } from "../../client/MapControls"; import houseCardAbilities from "./game-data-structure/house-card/houseCardAbilities"; +import SnrError from "../../utils/snrError"; export const NOTE_MAX_LENGTH = 5000; @@ -632,7 +633,7 @@ export default class IngameGameState extends GameState< const suzerainHouse = this.game.vassalRelations.tryGet(house, null); if (suzerainHouse == null) { - throw new Error(`getControllerOfHouse(${house.name}) failed as there is no suzerainHouse`); + throw new SnrError(this.entireGame, `getControllerOfHouse(${house.name}) failed as there is no suzerainHouse`); } return this.getControllerOfHouse(suzerainHouse); @@ -640,7 +641,7 @@ export default class IngameGameState extends GameState< const player = this.players.values.find(p => p.house == house); if (player == null) { - throw new Error(`getControllerOfHouse(${house.name}) failed due to a fatal error`); + throw new SnrError(this.entireGame, `getControllerOfHouse(${house.name}) failed due to a fatal error`); } return player; @@ -760,7 +761,7 @@ export default class IngameGameState extends GameState< try { if (!player.liveClockData) { - throw new Error("LiveClockData must be present in onPlayerClockTimeout"); + throw new SnrError(this.entireGame, "LiveClockData must be present in onPlayerClockTimeout"); } this.endPlayerClock(player, false); @@ -944,7 +945,7 @@ export default class IngameGameState extends GameState< } if (!newCommander) { - throw new Error("Unable to determine new commander"); + throw new SnrError(this.entireGame, "Unable to determine new commander"); } // It may happen that you replace a player which commands vassals. Assign them to the potential winner. @@ -1794,7 +1795,7 @@ export default class IngameGameState extends GameState< isVassalControlledByPlayer(vassal: House, player: Player): boolean { if (!this.isVassalHouse(vassal)) { - throw new Error(); + throw new SnrError(this.entireGame); } return this.game.vassalRelations.tryGet(vassal, null) == player.house; diff --git a/agot-bg-game-server/src/common/ingame-game-state/Player.ts b/agot-bg-game-server/src/common/ingame-game-state/Player.ts index e20e4e223..4f50a737c 100644 --- a/agot-bg-game-server/src/common/ingame-game-state/Player.ts +++ b/agot-bg-game-server/src/common/ingame-game-state/Player.ts @@ -4,6 +4,7 @@ import IngameGameState from "./IngameGameState"; import { VoteState } from "./vote-system/Vote"; import { observable } from "mobx"; import getElapsedSeconds, { getTimeDeltaInSeconds } from "../../utils/getElapsedSeconds"; +import SnrError from "../../utils/snrError"; export default class Player { user: User; @@ -17,7 +18,7 @@ export default class Player { get totalRemainingSeconds(): number { if (!this.liveClockData) { - throw new Error("totalRemainingSeconds requested but no liveClockData present"); + throw new SnrError(this.user.entireGame, "totalRemainingSeconds requested but no liveClockData present"); } let total = this.liveClockData.remainingSeconds; @@ -31,7 +32,7 @@ export default class Player { clientGetTotalRemainingSeconds(now: Date): number { if (!this.liveClockData) { - throw new Error("totalRemainingSeconds requested but no liveClockData present"); + throw new SnrError(this.user.entireGame, "totalRemainingSeconds requested but no liveClockData present"); } let total = this.liveClockData.remainingSeconds; diff --git a/agot-bg-game-server/src/common/ingame-game-state/action-game-state/resolve-consolidate-power-game-state/execute-loan-game-state/spymaster-game-state/SpymasterGameState.ts b/agot-bg-game-server/src/common/ingame-game-state/action-game-state/resolve-consolidate-power-game-state/execute-loan-game-state/spymaster-game-state/SpymasterGameState.ts index d624fa752..961cda19e 100644 --- a/agot-bg-game-server/src/common/ingame-game-state/action-game-state/resolve-consolidate-power-game-state/execute-loan-game-state/spymaster-game-state/SpymasterGameState.ts +++ b/agot-bg-game-server/src/common/ingame-game-state/action-game-state/resolve-consolidate-power-game-state/execute-loan-game-state/spymaster-game-state/SpymasterGameState.ts @@ -11,6 +11,7 @@ import BetterMap from "../../../../../../utils/BetterMap"; import ResolveSpymasterGameState, { SerializedResolveSpymasterGameState } from "./resolve-spymaster-game-state/ResolveSpymasterGameState"; import WesterosCard from "../../../../../ingame-game-state/game-data-structure/westeros-card/WesterosCard"; import _ from "lodash"; +import SnrError from "../../../../../../utils/snrError"; export default class SpymasterGameState extends GameState> { @@ -58,7 +59,7 @@ export default class SpymasterGameState extends GameState wc.discarded); @@ -67,7 +68,7 @@ export default class SpymasterGameState extends GameState !this.ingame.isVassalHouse(h)); if (nonVassalTrack.length == 0) { - throw new Error("There must be at least one non-vassal in the track"); + throw new SnrError(this.ingame.entireGame, "There must be at least one non-vassal in the track"); } return nonVassalTrack[0]; @@ -440,7 +441,7 @@ export default class Game { getHouseCardById(id: string): HouseCard { const allCards = this.getAllHouseCardsInGame(); if (!allCards.has(id)) { - throw new Error(`House card ${id} not found`); + throw new SnrError(this.ingame.entireGame, `House card ${id} not found`); } return allCards.get(id); } diff --git a/agot-bg-game-server/src/common/ingame-game-state/game-data-structure/Region.ts b/agot-bg-game-server/src/common/ingame-game-state/game-data-structure/Region.ts index 802cffd3d..ca569712b 100644 --- a/agot-bg-game-server/src/common/ingame-game-state/game-data-structure/Region.ts +++ b/agot-bg-game-server/src/common/ingame-game-state/game-data-structure/Region.ts @@ -10,6 +10,7 @@ import UnitSlot from "../../../utils/unitSlot"; import _ from "lodash"; import getStaticWorld from "./static-data-structure/getStaticWorld"; import { port } from "./regionTypes"; +import SnrError from "../../../utils/snrError"; export default class Region { game: Game; @@ -123,7 +124,7 @@ export default class Region { // have the same allegiance. const possibleController = this.units.values[0].allegiance; if (!this.units.values.every(u => u.allegiance == possibleController)) { - throw new Error( + throw new SnrError(this.game.ingame.entireGame, "getController was called on region \"" + this.id + "\" but multiple units of different allegiance are present in the region" ); } diff --git a/agot-bg-game-server/src/common/ingame-game-state/port-helper/PortHelper.ts b/agot-bg-game-server/src/common/ingame-game-state/port-helper/PortHelper.ts index c1671c645..24d41c503 100644 --- a/agot-bg-game-server/src/common/ingame-game-state/port-helper/PortHelper.ts +++ b/agot-bg-game-server/src/common/ingame-game-state/port-helper/PortHelper.ts @@ -82,7 +82,7 @@ export function isTakeControlOfEnemyPortGameStateRequired(ingame: IngameGameStat } // We should never reach this line because we removed orphaned ships earlier. - throw new Error(`$Port with id '{portRegion.id}' contains orphaned ships which should have been removed before!`); + throw new Error(`Port with id '${portRegion.id}' contains orphaned ships which should have been removed before!`); } export interface TakeControlOfEnemyPortResult { diff --git a/agot-bg-game-server/src/common/ingame-game-state/westeros-game-state/westeros-deck-4-game-state/move-loyalty-tokens-game-state/MoveLoyaltyTokensGameState.ts b/agot-bg-game-server/src/common/ingame-game-state/westeros-game-state/westeros-deck-4-game-state/move-loyalty-tokens-game-state/MoveLoyaltyTokensGameState.ts index 410e9aa7c..03d0e2c16 100644 --- a/agot-bg-game-server/src/common/ingame-game-state/westeros-game-state/westeros-deck-4-game-state/move-loyalty-tokens-game-state/MoveLoyaltyTokensGameState.ts +++ b/agot-bg-game-server/src/common/ingame-game-state/westeros-game-state/westeros-deck-4-game-state/move-loyalty-tokens-game-state/MoveLoyaltyTokensGameState.ts @@ -148,7 +148,7 @@ export default class MoveLoyaltyTokensGameState extends GameState