use thiserror::Error;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Error, Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum ImgFprintError {
#[error("decode failed: {0}")]
DecodeError(String),
#[error("invalid image: {0}")]
InvalidImage(String),
#[error("unsupported format: {0}")]
UnsupportedFormat(String),
#[error("processing error: {0}")]
ProcessingError(String),
#[error("image dimensions too small: {0}")]
ImageTooSmall(String),
#[error("embedding dimension mismatch: expected {expected}, got {actual}")]
EmbeddingDimensionMismatch {
expected: usize,
actual: usize,
},
#[error("embedding provider error: {0}")]
ProviderError(String),
#[error("invalid embedding: {0}")]
InvalidEmbedding(String),
#[error("io error: {0}")]
IoError(String),
}
impl From<std::io::Error> for ImgFprintError {
fn from(err: std::io::Error) -> Self {
Self::IoError(err.to_string())
}
}
impl ImgFprintError {
#[cold]
#[inline(never)]
pub fn decode_error(msg: impl Into<String>) -> Self {
Self::DecodeError(msg.into())
}
#[cold]
#[inline(never)]
pub fn invalid_image(msg: impl Into<String>) -> Self {
Self::InvalidImage(msg.into())
}
#[cold]
#[inline(never)]
pub fn processing_error(msg: impl Into<String>) -> Self {
Self::ProcessingError(msg.into())
}
#[cold]
#[inline(never)]
pub fn image_too_small(msg: impl Into<String>) -> Self {
Self::ImageTooSmall(msg.into())
}
}
const _: () = {
const fn assert_send<T: Send>() {}
const fn assert_sync<T: Sync>() {}
assert_send::<ImgFprintError>();
assert_sync::<ImgFprintError>();
};