Skip to main content

zsfm_core/
error.rs

1/// Typed validation errors for request parsing. Callers at the CLI edge
2/// convert these to `anyhow` with context; library code can match on variants.
3#[derive(Debug, thiserror::Error)]
4pub enum ValidationError {
5    #[error("context must be a non-empty array")]
6    EmptyContext,
7    #[error("context[{0}][{1}] must not be empty")]
8    EmptySeries(usize, usize),
9    #[error("context too large — got {0} values, max is {1}")]
10    ContextTooLarge(usize, usize),
11    #[error("context[{0}][{1}] must contain only finite numbers")]
12    NonFinite(usize, usize),
13    #[error("horizon must be a positive integer")]
14    BadHorizon,
15    #[error("horizon too large — got {0}, max is {1}")]
16    HorizonTooLarge(usize, usize),
17    #[error("stdin input too large — max is {0} bytes")]
18    StdinTooLarge(u64),
19    #[error("matrix must be a non-empty array")]
20    EmptyMatrix,
21    #[error("row {0} has inconsistent width")]
22    RaggedMatrix(usize),
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn displays() {
31        assert_eq!(
32            ValidationError::HorizonTooLarge(5000, 4096).to_string(),
33            "horizon too large — got 5000, max is 4096"
34        );
35    }
36}