[explorer, moves, core] Improve error handling in explorer
Implement thiserror::Error for a bunch of error types, and remove string errors from the implementation of the command handler in explorer. Clean up parsing of basic types all over the place. Update Cargo files to include thiserror and anyhow.
This commit is contained in:
parent
72eeba84ba
commit
9010f1e9c2
12 changed files with 331 additions and 226 deletions
|
@ -4,15 +4,20 @@ use crate::{defs::Kind, Move, PromotionShape};
|
|||
use chessfriend_board::{castle, en_passant::EnPassant};
|
||||
use chessfriend_core::{Color, File, PlacedPiece, Rank, Square};
|
||||
use std::result::Result as StdResult;
|
||||
use thiserror::Error;
|
||||
|
||||
pub type Result = std::result::Result<Move, Error>;
|
||||
type EncodedMoveResult = std::result::Result<u16, Error>;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Error, Eq, PartialEq)]
|
||||
pub enum Error {
|
||||
#[error("no origin square")]
|
||||
MissingOriginSquare,
|
||||
#[error("no target square")]
|
||||
MissingTargetSquare,
|
||||
#[error("no capture square")]
|
||||
MissingCaptureSquare,
|
||||
#[error("invalid en passant square")]
|
||||
InvalidEnPassantSquare,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue