ragdrift_core/error.rs
1//! Error type returned by all fallible ragdrift operations.
2
3use thiserror::Error;
4
5/// All errors raised by the core crate.
6#[derive(Debug, Error)]
7pub enum RagDriftError {
8 /// Two arrays were expected to share a dimension and did not.
9 #[error("dimension mismatch: expected {expected}, got {actual} ({context})")]
10 DimensionMismatch {
11 /// Expected size.
12 expected: usize,
13 /// Actual size.
14 actual: usize,
15 /// Where the mismatch was detected.
16 context: &'static str,
17 },
18
19 /// Not enough samples to run the detector.
20 #[error("insufficient samples: need at least {required}, got {got} ({context})")]
21 InsufficientSamples {
22 /// Minimum required.
23 required: usize,
24 /// Actual count.
25 got: usize,
26 /// Where the check happened.
27 context: &'static str,
28 },
29
30 /// A computation produced a non-finite value where it should have been finite.
31 #[error("numerical instability in {0} (NaN or infinity)")]
32 NumericalInstability(&'static str),
33
34 /// Invalid configuration value (e.g., negative threshold).
35 #[error("invalid configuration: {0}")]
36 InvalidConfig(String),
37
38 /// IO error while reading or writing a snapshot.
39 #[error("io error: {0}")]
40 Io(#[from] std::io::Error),
41
42 /// Serde error while serializing or deserializing a snapshot.
43 #[error("serialization error: {0}")]
44 Serde(#[from] serde_json::Error),
45}