Skip to main content

ragdrift_core/
error.rs

1//! Error type used across the crate.
2
3use thiserror::Error;
4
5/// Crate-wide result alias.
6pub type Result<T> = std::result::Result<T, RagDriftError>;
7
8/// All errors surfaced by ragdrift-core.
9#[derive(Error, Debug)]
10pub enum RagDriftError {
11    /// Baseline and current samples have incompatible shapes.
12    #[error("dimension mismatch: baseline={baseline:?}, current={current:?}")]
13    DimensionMismatch {
14        /// Shape of the baseline sample.
15        baseline: Vec<usize>,
16        /// Shape of the current sample.
17        current: Vec<usize>,
18    },
19
20    /// A sample is too small for the requested computation.
21    #[error("insufficient samples: needed at least {needed}, got {got}")]
22    InsufficientSamples {
23        /// Minimum required sample count.
24        needed: usize,
25        /// Actual sample count provided.
26        got: usize,
27    },
28
29    /// A numerical step produced NaN or +/-inf.
30    #[error("numerical instability in {step}: {reason}")]
31    NumericalInstability {
32        /// Name of the algorithm step.
33        step: String,
34        /// Free-form description.
35        reason: String,
36    },
37
38    /// An invalid configuration value was supplied.
39    #[error("invalid configuration: {0}")]
40    InvalidConfig(String),
41
42    /// I/O failure during snapshot save/load.
43    #[error("io error: {0}")]
44    Io(#[from] std::io::Error),
45
46    /// JSON serialization or deserialization failure.
47    #[error("serde error: {0}")]
48    Serde(#[from] serde_json::Error),
49}