werewolves/werewolves-proto/src/error.rs

79 lines
2.7 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
use thiserror::Error;
2025-10-04 17:50:29 +01:00
use crate::{message::PublicIdentity, player::PlayerId, role::RoleTitle};
#[derive(Debug, Clone, PartialEq, Error, Serialize, Deserialize)]
pub enum GameError {
2025-10-04 17:50:29 +01:00
#[error("too many roles. there's {players} players, but {roles} roles")]
TooManyRoles { players: u8, roles: u8 },
2025-10-04 17:50:29 +01:00
#[error("no wolves?")]
NoWolves,
#[error("message invalid for game state")]
InvalidMessageForGameState,
#[error("no executions during night time")]
NoExecutionsAtNight,
#[error("chracter is already dead")]
CharacterAlreadyDead,
#[error("no matching character found")]
NoMatchingCharacterFound,
#[error("character not in joined player pool")]
CharacterNotInJoinedPlayers,
#[error("{0}")]
GenericError(String),
#[error("invalid cause of death")]
InvalidCauseOfDeath,
#[error("invalid target")]
InvalidTarget,
#[error("timed out")]
TimedOut,
#[error("host channel closed")]
HostChannelClosed,
2025-10-04 17:50:29 +01:00
#[error("too many players: there's {got} players but only {need} roles")]
TooManyPlayers { got: u8, need: u8 },
#[error("it's already daytime")]
AlreadyDaytime,
#[error("it's not the end of the night yet")]
NotEndOfNight,
#[error("it's not day yet")]
NotDayYet,
#[error("it's not night")]
NotNight,
#[error("invalid role, expected {expected:?} got {got:?}")]
InvalidRole { expected: RoleTitle, got: RoleTitle },
#[error("no mentor for an apprentice to be an apprentice to :(")]
NoApprenticeMentor,
2025-10-04 17:50:29 +01:00
#[error("{0} isn't a mentor role")]
NotAMentor(RoleTitle),
#[error("inactive game object")]
InactiveGameObject,
#[error("socket error: {0}")]
SocketError(String),
#[error("this night is over")]
NightOver,
#[error("no night actions")]
NoNightActions,
#[error("still awaiting response")]
AwaitingResponse,
#[error("current state already has a response")]
NightNeedsNext,
#[error("night zero actions can only be obtained on night zero")]
NotNightZero,
#[error("wolves intro in progress")]
WolvesIntroInProgress,
#[error("a game is still ongoing")]
GameOngoing,
#[error("needs a role reveal")]
NeedRoleReveal,
#[error("no previous state")]
NoPreviousState,
#[error("invalid original kill for guardian guard")]
GuardianInvalidOriginalKill,
#[error("player not assigned number: {0}")]
PlayerNotAssignedNumber(String),
2025-10-04 17:50:29 +01:00
#[error("player [{0}] has an assigned role slot, but isn't in the player list")]
AssignedPlayerMissing(PlayerId),
#[error(" {0} assigned to {1} roles")]
AssignedMultipleTimes(PublicIdentity, usize),
}