1use thiserror::Error;
4
5pub type ModelResult<T> = Result<T, ModelError>;
7
8#[derive(Error, Debug)]
10pub enum ModelError {
11 #[error("missing tensor: {name}")]
13 MissingTensor { name: String },
14
15 #[error("shape mismatch for '{name}': expected {expected:?}, got {actual:?}")]
17 ShapeMismatch {
18 name: String,
19 expected: Vec<usize>,
20 actual: Vec<usize>,
21 },
22
23 #[error("sequence length {seq_len} exceeds max context {max_ctx}")]
25 SequenceTooLong { seq_len: usize, max_ctx: usize },
26
27 #[error("core: {0}")]
29 Core(#[from] oxibonsai_core::error::BonsaiError),
30
31 #[error("kernel: {0}")]
33 Kernel(#[from] oxibonsai_kernels::error::KernelError),
34
35 #[error("internal: {0}")]
37 Internal(String),
38}
39
40impl ModelError {
41 pub fn error_code(&self) -> &str {
43 match self {
44 Self::MissingTensor { .. } => "MISSING_TENSOR",
45 Self::ShapeMismatch { .. } => "SHAPE_MISMATCH",
46 Self::SequenceTooLong { .. } => "SEQUENCE_TOO_LONG",
47 Self::Core(_) => "CORE_ERROR",
48 Self::Kernel(_) => "KERNEL_ERROR",
49 Self::Internal(_) => "INTERNAL_ERROR",
50 }
51 }
52}