1use thiserror::Error;
2
3fn color_to_str(c: chess::Color) -> String {
4 match c {
5 chess::Color::White => "White".to_string(),
6 chess::Color::Black => "Black".to_string(),
7 }
8}
9
10#[derive(Clone, Debug, Error)]
11pub enum Error {
12 #[error("Invalid Game BFEN")]
14 GameParseError(String),
15
16 #[error("Invalid Board BFEN: {0}")]
17 BoardParseError(String),
18
19 #[error("Illegal move: {0}")]
20 IllegalMove(String),
21
22 #[error("Can't parse move: {0}")]
23 MoveParseError(String),
24
25 #[error("Unheld Drop: {} {1}", color_to_str(*.0))]
26 UnheldDrop(chess::Color, chess::Piece),
27
28 #[error("Invalid holdings: {0}")]
29 HoldingsParseError(String),
30
31 #[error("Chess Error: {0}")]
32 Chess(chess::Error),
33}
34
35impl From<chess::Error> for Error {
36 fn from(err: chess::Error) -> Self {
37 Error::Chess(err)
38 }
39}