oxibonsai_kernels/
error.rs1use thiserror::Error;
4
5pub type KernelResult<T> = Result<T, KernelError>;
7
8#[derive(Error, Debug)]
10pub enum KernelError {
11 #[error("dimension mismatch: expected {expected}, got {got}")]
13 DimensionMismatch { expected: usize, got: usize },
14
15 #[error("output buffer too small: need {needed} elements, have {available}")]
17 BufferTooSmall { needed: usize, available: usize },
18
19 #[error("{count} elements is not divisible by block size {block_size}")]
21 NotBlockAligned { count: usize, block_size: usize },
22
23 #[error("core error: {0}")]
25 Core(#[from] oxibonsai_core::error::BonsaiError),
26
27 #[error("unsupported operation: {0}")]
29 UnsupportedOperation(String),
30
31 #[error("GPU error: {0}")]
33 GpuError(String),
34}
35
36impl KernelError {
37 pub fn error_code(&self) -> &str {
39 match self {
40 Self::DimensionMismatch { .. } => "DIMENSION_MISMATCH",
41 Self::BufferTooSmall { .. } => "BUFFER_TOO_SMALL",
42 Self::NotBlockAligned { .. } => "NOT_BLOCK_ALIGNED",
43 Self::Core(_) => "CORE_ERROR",
44 Self::UnsupportedOperation(_) => "UNSUPPORTED_OPERATION",
45 Self::GpuError(_) => "GPU_ERROR",
46 }
47 }
48}