diff --git a/src/board/chess_board/mod.rs b/src/board/chess_board/mod.rs index d51eabb..d1d3751 100644 --- a/src/board/chess_board/mod.rs +++ b/src/board/chess_board/mod.rs @@ -485,8 +485,8 @@ impl FromFen for ChessBoard { side, }; - if !res.is_valid() { - return Err(FenError::InvalidPosition); + if let Err(err) = res.validate() { + return Err(FenError::InvalidPosition(err)); } Ok(res) diff --git a/src/fen.rs b/src/fen.rs index d8af180..3034003 100644 --- a/src/fen.rs +++ b/src/fen.rs @@ -1,4 +1,4 @@ -use crate::board::{CastleRights, Color, File, Piece, Rank, Square}; +use crate::board::{CastleRights, Color, File, InvalidError, Piece, Rank, Square}; /// A trait to mark items that can be converted from a FEN input. pub trait FromFen: Sized { @@ -13,16 +13,15 @@ pub enum FenError { /// Invalid FEN input. InvalidFen, /// Invalid chess position. - InvalidPosition, + InvalidPosition(InvalidError), } impl std::fmt::Display for FenError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let error_msg = match self { - Self::InvalidFen => "Invalid FEN input", - Self::InvalidPosition => "Invalid chess position", - }; - write!(f, "{}", error_msg) + match self { + Self::InvalidFen => write!(f, "Invalid FEN input"), + Self::InvalidPosition(err) => write!(f, "Invalid chess position: {}", err), + } } }