Skip to main content

sensorlm/
error.rs

1//! Crate-wide error types.
2
3use thiserror::Error;
4
5/// All errors that can arise in `sensorlm-rs`.
6#[derive(Debug, Error)]
7pub enum SensorLMError {
8    /// A tensor shape did not match expectations.
9    #[error("Shape mismatch: expected {expected:?}, got {actual:?}")]
10    ShapeMismatch {
11        /// The shape that was required.
12        expected: Vec<usize>,
13        /// The shape that was actually observed.
14        actual: Vec<usize>,
15    },
16
17    /// A captioning operation failed.
18    #[error("Caption generation failed: {0}")]
19    CaptionError(String),
20
21    /// Dataset loading / parsing failed.
22    #[error("Dataset error: {0}")]
23    DatasetError(String),
24
25    /// HTTP download failed.
26    #[error("Download failed for '{url}': {source}")]
27    DownloadError {
28        /// The URL that was being fetched.
29        url: String,
30        /// The underlying reqwest error.
31        #[source]
32        source: reqwest::Error,
33    },
34
35    /// File I/O error.
36    #[error("I/O error: {0}")]
37    Io(#[from] std::io::Error),
38
39    /// JSON (de)serialisation error.
40    #[error("JSON error: {0}")]
41    Json(#[from] serde_json::Error),
42
43    /// Tokeniser error (opaque string from the `tokenizers` crate).
44    #[error("Tokeniser error: {0}")]
45    TokenizerError(String),
46
47    /// Quantisation calibration error.
48    #[error("Quantisation error: {0}")]
49    QuantisationError(String),
50
51    /// Generic catch-all from `anyhow`.
52    #[error(transparent)]
53    Other(#[from] anyhow::Error),
54}
55
56/// Shorthand result type used throughout the crate.
57pub type Result<T> = std::result::Result<T, SensorLMError>;