Skip to main content

llama_gguf/model/
error.rs

1//! Model-related error types
2
3use crate::tensor::DType;
4
5#[derive(thiserror::Error, Debug)]
6pub enum ModelError {
7    #[error("Unsupported architecture: {0}")]
8    UnsupportedArchitecture(String),
9
10    #[error("Missing tensor: {0}")]
11    MissingTensor(String),
12
13    #[error("Tensor shape mismatch for {name}: expected {expected:?}, got {got:?}")]
14    TensorShapeMismatch {
15        name: String,
16        expected: Vec<usize>,
17        got: Vec<usize>,
18    },
19
20    #[error("Tensor dtype mismatch for {name}: expected {expected:?}, got {got:?}")]
21    TensorDTypeMismatch {
22        name: String,
23        expected: DType,
24        got: DType,
25    },
26
27    #[error("Missing metadata: {0}")]
28    MissingMetadata(String),
29
30    #[error("Invalid metadata value for {key}: {message}")]
31    InvalidMetadata { key: String, message: String },
32
33    #[error("Configuration error: {0}")]
34    ConfigError(String),
35
36    #[error("Context length exceeded: {current} > {max}")]
37    ContextLengthExceeded { current: usize, max: usize },
38
39    #[error("KV cache error: {0}")]
40    KVCacheError(String),
41
42    #[error("Backend error: {0}")]
43    Backend(#[from] crate::backend::BackendError),
44
45    #[error("GGUF error: {0}")]
46    Gguf(#[from] crate::gguf::GgufError),
47
48    #[error("Tensor error: {0}")]
49    Tensor(#[from] crate::tensor::TensorError),
50
51    #[error("IO error: {0}")]
52    Io(#[from] std::io::Error),
53}
54
55pub type ModelResult<T> = Result<T, ModelError>;