server/domain/error.rs
1use thiserror::Error;
2
3use crate::domain::{Card, Player};
4
5/// Domain-specific errors that represent invalid game actions.
6///
7/// These errors are returned when a player attempts an illegal move according
8/// to the rules of the game (e.g. playing out of turn, invalid discard, etc.).
9#[derive(Debug, Error, PartialEq, Eq)]
10pub enum DomainError {
11 /// The host and guest must be different users.
12 #[error("invalid opponent")]
13 InvalidOpponent,
14
15 /// The user is not permitted to perform the action, i.e. they are not
16 /// a player in the game, or they are trying a command in the inccorect
17 /// phase in the game.
18 #[error("{0} is not permitted")]
19 NotPermitted(String),
20
21 /// The user is discarding cards they do not own, or too many or too few cards.
22 #[error("invalid discards: {0}")]
23 InvalidDiscards(String),
24
25 /// The user is making a `Play` or `Go` when it is not their turn.
26 #[error("not the player's turn: {0}")]
27 NotPlayersTurn(Player),
28
29 /// The user is playing card they do not own, or that will make the
30 /// running total > 31.
31 #[error("invalid play: {0}")]
32 InvalidPlay(Card),
33
34 /// The user is declaring `Go` even though they have a valid card that
35 /// must be played.
36 #[error("invalid go: some cards are playable")]
37 InvalidGo,
38}