chess/
error.rs

1use thiserror::Error;
2
3use crate::{Board, ChessMove};
4
5/// Error that can happen during the game.
6///
7/// derive from PartialEq for UnitTest
8#[derive(Error, Clone, PartialEq, Eq, Debug)]
9pub enum Error {
10    /// The move on a particular board doesn't respect the chess rules.
11    #[error(
12        "Invalid move ({}) on the given board ({}) according to the chess rule",
13        invalid_move,
14        board
15    )]
16    InvalidMove {
17        board: Board,
18        invalid_move: ChessMove,
19    },
20
21    /// The FEN (Forsyth-Edwards Notation) string is invalid.
22    #[error("Invalid FEN string: {}", fen)]
23    InvalidFen { fen: String },
24
25    /// An attempt was made to create a move from an invalid SAN string.
26    #[error("The string specified does not contain a valid SAN notation move")]
27    InvalidSanMove,
28
29    /// An attempt was made to create a square from an invalid string.
30    #[error("The string specified does not contain a valid algebraic notation square")]
31    InvalidSquare,
32
33    /// An attempt was made to convert a string not equal to "1"-"8" to a rank.
34    #[error("The string specified does not contain a valid rank")]
35    InvalidRank,
36
37    /// An attempt was made to convert a string not equal to "a"-"h" to a file.
38    #[error("The string specified does not contain a valid file")]
39    InvalidFile,
40}