Skip to content

Commit

Permalink
Merge pull request #556 from tonybaloney/invalid_state_exceptions
Browse files Browse the repository at this point in the history
Add extra info to invalid state exceptions
  • Loading branch information
tonybaloney authored Apr 8, 2024
2 parents fea5685 + e44f8f1 commit 5e31b18
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/panel/basepettype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ 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;
}
}

export abstract class BasePetType implements IPetType {
label: string = 'base';
Expand Down Expand Up @@ -242,7 +251,7 @@ export abstract class BasePetType implements IPetType {
}
}
if (!possibleNextStates) {
throw new InvalidStateException();
throw new InvalidStateError(fromState, this.label);
}
// randomly choose the next state
const idx = Math.floor(Math.random() * possibleNextStates.length);
Expand Down

0 comments on commit 5e31b18

Please sign in to comment.