Skip to main content

littlebit_models/
error.rs

1//! Typed errors for `littlebit-models`.
2
3use thiserror::Error;
4
5/// Result alias for `littlebit-models` operations.
6pub type Result<T> = std::result::Result<T, ModelError>;
7
8/// Errors produced during model configuration parsing, architecture construction,
9/// LittleBit patching, generation, or Hugging Face Hub I/O.
10#[derive(Debug, Error)]
11pub enum ModelError {
12    /// Error propagated from `littlebit-core`.
13    #[error(transparent)]
14    Core(#[from] littlebit_core::LittleBitError),
15
16    /// Underlying Candle tensor operation failed.
17    #[error("tensor operation failed: {0}")]
18    Candle(#[from] candle_core::Error),
19
20    /// Filesystem I/O failure.
21    #[error("i/o error: {0}")]
22    Io(#[from] std::io::Error),
23
24    /// JSON config parsing or serialization failure.
25    #[error("json error: {0}")]
26    Json(#[from] serde_json::Error),
27
28    /// Hugging Face Hub client error.
29    #[error("huggingface hub error: {0}")]
30    Hub(#[from] hf_hub::HFError),
31
32    /// Unsupported model architecture or invalid `config.json`.
33    #[error("unsupported or invalid model config: {0}")]
34    UnsupportedArchitecture(String),
35
36    /// Missing required tensor weight in checkpoint.
37    #[error("missing model tensor `{0}`")]
38    MissingWeight(String),
39
40    /// Invalid generation or patching argument.
41    #[error("invalid argument: {0}")]
42    InvalidArgument(String),
43}
44
45const _: () = {
46    const fn assert_send_sync<T: Send + Sync + 'static>() {}
47    assert_send_sync::<ModelError>();
48};