use thiserror::Error;
pub type KernelResult<T> = Result<T, KernelError>;
#[derive(Error, Debug)]
pub enum KernelError {
#[error("dimension mismatch: expected {expected}, got {got}")]
DimensionMismatch { expected: usize, got: usize },
#[error("output buffer too small: need {needed} elements, have {available}")]
BufferTooSmall { needed: usize, available: usize },
#[error("{count} elements is not divisible by block size {block_size}")]
NotBlockAligned { count: usize, block_size: usize },
#[error("core error: {0}")]
Core(#[from] oxibonsai_core::error::BonsaiError),
#[error("unsupported operation: {0}")]
UnsupportedOperation(String),
#[error("GPU error: {0}")]
GpuError(String),
}
impl KernelError {
pub fn error_code(&self) -> &str {
match self {
Self::DimensionMismatch { .. } => "DIMENSION_MISMATCH",
Self::BufferTooSmall { .. } => "BUFFER_TOO_SMALL",
Self::NotBlockAligned { .. } => "NOT_BLOCK_ALIGNED",
Self::Core(_) => "CORE_ERROR",
Self::UnsupportedOperation(_) => "UNSUPPORTED_OPERATION",
Self::GpuError(_) => "GPU_ERROR",
}
}
}