Skip to main content

sisyphus32/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum FenParseError {
5    #[error("Couldn't find fen pieces")]
6    NoPieces,
7    
8    #[error("Couldn't find fen side")]
9    NoSide,
10    
11    #[error("Couldn't find fen castling rights")]
12    NoCastlingRights,
13    
14    #[error("Couldn't find fen en-passant square")]
15    NoEnPassant,
16    
17    #[error("Couldn't parse fen pieces: {0}")]
18    Pieces(String),
19    
20    #[error("Couldn't parse fen side: {0}")]
21    Side(String),
22    
23    #[error("Couldn't parse fen castling rights: {0}")]
24    CastlingRights(char),
25    
26    #[error("Couldn't parse fen en-passant square: {0}")]
27    EnPassant(#[from] SquareParseError),
28    
29    #[error("Couldn't parse illegal piece: {0}")]
30    IllegalPiece(char),
31}
32
33#[derive(Error, Debug)]
34#[error("Couldn't parse file: {0}")]
35pub struct FileParseError(pub char);
36
37#[derive(Error, Debug)]
38#[error("Couldn't parse rank: {0}")]
39pub struct RankParseError(pub char);
40
41#[derive(Error, Debug)]
42pub enum UciParseError {
43    #[error("Couldn't parse uci keyword")]
44    Keyword,
45
46    #[error("Couldn't parse parameter: {0}")]
47    Param(&'static str),
48
49    #[error("Couldn't parse parameter value: {0}")]
50    ParamValue(&'static str),
51
52    #[error("Parameter out of range for: {0}")]
53    ParamRange(&'static str),
54
55    #[error("Couldn't parse uci option")]
56    Option,
57
58    #[error("{0}")]
59    MoveStringParseError(#[from] MoveStringParseError),
60
61    #[error("{0}")]
62    FenParseError(#[from] FenParseError),
63
64    #[error("Disabled feature: {0}")]
65    DisabledFeatureError(&'static str),
66}
67
68#[derive(Error, Debug)]
69pub enum MoveStringParseError {
70    #[error("Illegal move string length")]
71    LengthParseError,
72
73    #[error("Illegal promotion piece")]
74    PromotionPieceParseError(String),
75    
76    #[error("Couldn't find pseudo-legal move: {0}")]
77    IllegalMove(String),
78
79    #[error("{0}")]
80    SquareParseError(#[from] SquareParseError),
81}
82
83#[derive(Error, Debug)]
84pub enum SquareParseError {
85    #[error("Missing file character")]
86    NoFile,
87
88    #[error("Missing rank character")]
89    NoRank,
90
91    #[error("Illegal string length for square: {0}")]
92    StringLength(String),
93
94    #[error("{0}")]
95    RankParseError(#[from] RankParseError),
96
97    #[error("{0}")]
98    FileParseError(#[from] FileParseError),
99}
100
101#[derive(Error, Debug)]
102pub enum BotGameError {
103    #[error("Illegal UCI move")]
104    IllegalUciMoveError,
105
106    #[error("Player performed illegal action")]
107    IllegalActionError,
108}