//! Error types for Candle integration use thiserror::Error; /// Result type for Candle operations pub type Result = std::result::Result; /// Errors that can occur in Candle integration #[derive(Debug, Error)] pub enum CandleError { /// Failed to load model #[error("Failed to load model: {0}")] ModelLoad(String), /// Failed to create session #[error("Failed to create session: {0}")] SessionCreation(String), /// Inference failed #[error("Inference failed: {0}")] Inference(String), /// Tensor conversion error #[error("Tensor conversion error: {0}")] TensorConversion(String), /// Backend not available #[error("Backend not available: {0}")] BackendUnavailable(String), /// Shape mismatch #[error("Shape mismatch: expected {expected:?}, got {actual:?}")] ShapeMismatch { expected: Vec, actual: Vec, }, /// Unsupported data type #[error("Unsupported data type: {0}")] UnsupportedDType(String), /// `HuggingFace` Hub error #[error("Hub error: {0}")] Hub(String), /// Tokenization error #[error("Tokenization error: {0}")] Tokenization(String), /// IO error #[error("IO error: {0}")] Io(#[from] std::io::Error), /// Candle core error #[error("Candle error: {0}")] Candle(String), /// `SafeTensors` error #[error("SafeTensors error: {0}")] SafeTensors(String), } impl CandleError { /// Create a model load error pub fn model_load(msg: impl Into) -> Self { Self::ModelLoad(msg.into()) } /// Create a tensor conversion error pub fn tensor_conversion(msg: impl Into) -> Self { Self::TensorConversion(msg.into()) } /// Create a hub error pub fn hub(msg: impl Into) -> Self { Self::Hub(msg.into()) } /// Create a shape mismatch error pub fn shape_mismatch(expected: Vec, actual: Vec) -> Self { Self::ShapeMismatch { expected, actual } } } impl From for CandleError { fn from(err: candle_core::Error) -> Self { Self::Candle(err.to_string()) } } impl From for CandleError { fn from(err: safetensors::SafeTensorError) -> Self { Self::SafeTensors(err.to_string()) } }