From bc3d415db8efdbd13bd15bcade59c49d19992b35 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Mon, 8 Apr 2024 09:31:24 +1000 Subject: [PATCH 1/3] Find invalid state exceptions --- src/panel/basepettype.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/panel/basepettype.ts b/src/panel/basepettype.ts index 55ebeba7..9a08c9f2 100644 --- a/src/panel/basepettype.ts +++ b/src/panel/basepettype.ts @@ -1,4 +1,4 @@ -import { PetColor, PetSize, PetSpeed } from '../common/types'; +import { PetColor, PetSize, PetSpeed, PetType } from '../common/types'; import { IPetType } from './states'; import { ISequenceTree } from './sequences'; import { @@ -13,7 +13,15 @@ import { FrameResult, } from './states'; -export class InvalidStateException {} +export class InvalidStateException { + fromState: States; + petType: string; + + constructor(fromState: States, petType: string) { + this.fromState = fromState; + this.petType = petType; + } +} export abstract class BasePetType implements IPetType { label: string = 'base'; @@ -242,7 +250,7 @@ export abstract class BasePetType implements IPetType { } } if (!possibleNextStates) { - throw new InvalidStateException(); + throw new InvalidStateException(fromState, this.label); } // randomly choose the next state const idx = Math.floor(Math.random() * possibleNextStates.length); From b9f670400b45b20a3b4d03a964482a6fccb52134 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Mon, 8 Apr 2024 09:33:13 +1000 Subject: [PATCH 2/3] Remove unused import --- src/panel/basepettype.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panel/basepettype.ts b/src/panel/basepettype.ts index 9a08c9f2..fb91c899 100644 --- a/src/panel/basepettype.ts +++ b/src/panel/basepettype.ts @@ -1,4 +1,4 @@ -import { PetColor, PetSize, PetSpeed, PetType } from '../common/types'; +import { PetColor, PetSize, PetSpeed } from '../common/types'; import { IPetType } from './states'; import { ISequenceTree } from './sequences'; import { From e44f8f18f610b6152f002d453df72f0defd875f7 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Mon, 8 Apr 2024 09:43:18 +1000 Subject: [PATCH 3/3] Use base error --- src/panel/basepettype.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/panel/basepettype.ts b/src/panel/basepettype.ts index fb91c899..732bca92 100644 --- a/src/panel/basepettype.ts +++ b/src/panel/basepettype.ts @@ -13,11 +13,12 @@ import { FrameResult, } from './states'; -export class InvalidStateException { +export class InvalidStateError extends Error { fromState: States; petType: string; constructor(fromState: States, petType: string) { + super(`Invalid state ${fromState} for pet type ${petType}`); this.fromState = fromState; this.petType = petType; } @@ -250,7 +251,7 @@ export abstract class BasePetType implements IPetType { } } if (!possibleNextStates) { - throw new InvalidStateException(fromState, this.label); + throw new InvalidStateError(fromState, this.label); } // randomly choose the next state const idx = Math.floor(Math.random() * possibleNextStates.length);