//! Error types for RustyBooks integration use thiserror::Error; /// Errors that can occur during RustyBooks integration operations #[derive(Error, Debug)] pub enum IntegrationError { /// GPU device not available #[error("GPU device not available: {0}")] DeviceNotAvailable(String), /// Memory allocation failed #[error("Memory allocation failed: requested {requested} bytes, available {available}")] AllocationFailed { requested: usize, available: usize }, /// Storage I/O error #[error("Storage I/O error: {0}")] StorageError(String), /// Transfer error #[error("Transfer error: {0}")] TransferError(String), /// Profiling error #[error("Profiling error: {0}")] ProfilingError(String), /// Kernel execution error #[error("Kernel execution error: {0}")] KernelError(String), /// Shape mismatch #[error("Shape mismatch: expected {expected}, got {actual}")] ShapeMismatch { expected: String, actual: String }, /// Feature not available #[error("Feature not available: {0}")] FeatureNotAvailable(String), /// Backend error from gpu-direct #[cfg(feature = "direct-storage")] #[error("gpu-direct error: {0}")] GpuDirectError(#[from] gpu_direct::metal::MetalError), /// Backend error from gpu-profiler #[cfg(feature = "profiling")] #[error("gpu-profiler error: {0}")] GpuProfilerError(#[from] gpu_profiler::metal::ProfilerError), /// Backend error from tensor-accelerator #[cfg(feature = "tma")] #[error("tensor-accelerator error: {0}")] TensorAcceleratorError(#[from] tensor_accelerator::metal::TensorError), /// Generic error #[error("{0}")] Other(String), } /// Result type for RustyBooks integration pub type Result = std::result::Result; impl From for IntegrationError { fn from(err: std::io::Error) -> Self { IntegrationError::StorageError(err.to_string()) } } impl From for IntegrationError { fn from(err: anyhow::Error) -> Self { IntegrationError::Other(err.to_string()) } }