wordle-analyzer/src/error.rs
Christoph J. Scherr 18a5125028
All checks were successful
cargo devel CI / cargo CI (push) Successful in 1m58s
fix(evaluation): evaluation did not get built from string correctly #9
2024-07-25 14:48:16 +02:00

70 lines
1.8 KiB
Rust

use thiserror::Error;
use crate::bench::report::Report;
use crate::wlist::word::Word;
pub type WResult<T> = std::result::Result<T, Error>;
pub type GameResult<T> = std::result::Result<T, GameError>;
#[derive(Debug, Error)]
pub enum Error {
#[error("Game Error")]
GameError {
#[from]
source: GameError,
},
#[error("Solver Error")]
SolverError {
#[from]
source: SolverError,
},
#[error("Benchmark Error")]
BenchError {
#[from]
source: BenchError,
},
#[error(transparent)]
Other {
#[from]
source: anyhow::Error,
},
// for `FromStr` of `BuiltinSolver`
#[error("Unknown builtin solver")]
UnknownBuiltinSolver,
#[error("pattern matching error")]
Regex {
#[from]
source: regex::Error,
},
#[error("Error sharing the benchmark data over multiple threads")]
Mutex {
#[from]
source: std::sync::PoisonError<Report>,
},
}
#[derive(Debug, Clone, Error)]
pub enum GameError {
#[error("The guess has the wrong length ({0})")]
GuessHasWrongLength(usize),
#[error("The game is finished but a guess is being made")]
TryingToPlayAFinishedGame,
#[error("Tried to guess or use a word that is not in the wordlist ({0})")]
WordNotInWordlist(Word),
#[error("Invalid syntax for manual evaluation creation")]
InvalidEvaluationSyntax(String),
#[error("The length of guess and evaluation must be the same")]
GuessAndEvalNotSameLen((String, String)),
}
#[derive(Debug, Clone, Error)]
pub enum BenchError {
#[error("Trying to modify a finished report")]
ModifyFinishedReport,
}
#[derive(Debug, Clone, Error)]
pub enum SolverError {
#[error("Wordlist has no matches for the gamestate")]
NoMatches,
}