werewolves/werewolves-proto/src/error.rs

99 lines
3.6 KiB
Rust

// Copyright (C) 2025 Emilis Bliūdžius
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::{game::GameTime, message::PublicIdentity, player::PlayerId, role::RoleTitle};
#[derive(Debug, Clone, PartialEq, Error, Serialize, Deserialize)]
pub enum GameError {
#[error("too many roles. there's {players} players, but {roles} roles")]
TooManyRoles { players: u8, roles: u8 },
#[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,
#[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,
#[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),
#[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),
#[error("change set for {0} is already set")]
ChangesAlreadySet(GameTime),
#[error("missing {0} in game story")]
MissingTime(GameTime),
#[error("no previous during day")]
NoPreviousDuringDay,
}