use crate::upscale::UpscaleError;
use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum ChessError {
DimensionMismatch {
expected: usize,
actual: usize,
},
Upscale(UpscaleError),
#[cfg(feature = "ml-refiner")]
RoiRefinerUnsupported,
}
impl fmt::Display for ChessError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DimensionMismatch { expected, actual } => write!(
f,
"image buffer length mismatch: expected {expected} bytes (width*height), got {actual}"
),
Self::Upscale(e) => write!(f, "upscale error: {e}"),
#[cfg(feature = "ml-refiner")]
Self::RoiRefinerUnsupported => write!(
f,
"configured refiner is not supported on the ROI detection path; \
select center-of-mass, Förstner, or saddle-point, or use the \
whole-image detect entry point"
),
}
}
}
impl std::error::Error for ChessError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Upscale(e) => Some(e),
_ => None,
}
}
}
impl From<UpscaleError> for ChessError {
fn from(e: UpscaleError) -> Self {
Self::Upscale(e)
}
}