use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum GeneralError {
#[error("Invalid argument: {0}")]
InvalidArgument(String),
#[error("IO error: {0}")]
IoError(String),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("Runtime error: {0}")]
RuntimeError(String),
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("Iteration error: {0}")]
IterationError(String),
#[error("Not implemented: {0}")]
NotImplemented(String),
#[error("Invalid operation: {0}")]
InvalidOperation(String),
#[error("Invalid state: {0}")]
InvalidState(String),
#[error("{0}")]
Other(String),
#[error("Device mismatch: tensors must be on the same device")]
DeviceMismatch,
#[error("Unsupported operation '{op}' for data type '{dtype}'")]
UnsupportedOperation { op: String, dtype: String },
#[error("Backend error: {0}")]
BackendError(String),
#[error("Device error: {0}")]
DeviceError(String),
#[error("Memory allocation failed: {0}")]
AllocationError(String),
#[error("Autograd error: {0}")]
AutogradError(String),
#[error("Type mismatch: expected {expected}, got {actual}")]
TypeMismatch { expected: String, actual: String },
#[error("Dimension error: {0}")]
DimensionError(String),
#[error("Threading error: {0}")]
ThreadError(String),
#[error("Thread synchronization error: {0}")]
SynchronizationError(String),
#[error("Numeric conversion error: {0}")]
ConversionError(String),
#[error("Data loading error: {0}")]
DataError(String),
#[error("Model error: {0}")]
ModelError(String),
#[error("Security error: {0}")]
SecurityError(String),
#[error("SciRS2 error: {0}")]
SciRS2Error(String),
#[error("Compute error: {0}")]
ComputeError(String),
}
impl GeneralError {
pub fn category(&self) -> crate::error::core::ErrorCategory {
match self {
Self::IoError(_) => crate::error::core::ErrorCategory::Io,
Self::ConfigError(_) => crate::error::core::ErrorCategory::Configuration,
Self::DeviceMismatch | Self::DeviceError(_) | Self::BackendError(_) => {
crate::error::core::ErrorCategory::Device
}
Self::AllocationError(_) => crate::error::core::ErrorCategory::Memory,
Self::TypeMismatch { .. } | Self::ConversionError(_) => {
crate::error::core::ErrorCategory::DataType
}
Self::ThreadError(_) | Self::SynchronizationError(_) => {
crate::error::core::ErrorCategory::Threading
}
Self::InvalidArgument(_) => crate::error::core::ErrorCategory::UserInput,
_ => crate::error::core::ErrorCategory::Internal,
}
}
}