matrix_rain/error.rs
1//! Error types returned by the builder and config validation.
2
3use thiserror::Error;
4
5/// Errors produced by [`MatrixConfigBuilder::build`](crate::MatrixConfigBuilder::build)
6/// and related validation routines.
7#[derive(Debug, Error)]
8pub enum MatrixError {
9 /// A configuration value failed its invariant check (e.g. `fps < 1`,
10 /// non-finite `speed`, `density` outside `[0.0, 1.0]`, `min_trail > max_trail`).
11 /// The string carries a human-readable description of which field and why.
12 #[error("invalid configuration: {0}")]
13 InvalidConfig(/// Reason the config was rejected.
14 String),
15
16 /// The configured [`CharSet`](crate::CharSet) resolves to zero glyphs.
17 /// Only [`CharSet::Custom`](crate::CharSet::Custom) with an empty `Vec`
18 /// can hit this — the built-in variants always resolve to non-empty
19 /// lists.
20 #[error("empty character set")]
21 EmptyCharset,
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn invalid_config_renders_message() {
30 let e = MatrixError::InvalidConfig("fps must be >= 1".into());
31 assert_eq!(e.to_string(), "invalid configuration: fps must be >= 1");
32 }
33
34 #[test]
35 fn empty_charset_renders_message() {
36 assert_eq!(MatrixError::EmptyCharset.to_string(), "empty character set");
37 }
38}