Skip to main content

ferro_theme/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during theme loading.
4#[derive(Debug, Error)]
5pub enum ThemeError {
6    /// Filesystem read failure.
7    #[error("failed to read theme file: {0}")]
8    Io(#[from] std::io::Error),
9
10    /// JSON parse failure when reading theme.json.
11    #[error("failed to parse theme.json: {0}")]
12    Json(#[from] serde_json::Error),
13
14    /// Theme directory not found at the given path.
15    #[error("theme not found: {0}")]
16    NotFound(String),
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn theme_error_io_wraps_std_io_error() {
25        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file missing");
26        let err = ThemeError::Io(io_err);
27        assert!(matches!(err, ThemeError::Io(_)));
28        assert!(err.to_string().contains("failed to read theme file"));
29    }
30
31    #[test]
32    fn theme_error_json_wraps_serde_json_error() {
33        let json_err = serde_json::from_str::<serde_json::Value>("{{not json").unwrap_err();
34        let err = ThemeError::Json(json_err);
35        assert!(matches!(err, ThemeError::Json(_)));
36        assert!(err.to_string().contains("failed to parse theme.json"));
37    }
38
39    #[test]
40    fn theme_error_not_found_contains_path_string() {
41        let err = ThemeError::NotFound("/some/path".to_string());
42        assert!(matches!(err, ThemeError::NotFound(_)));
43        let msg = err.to_string();
44        assert!(msg.contains("theme not found"));
45        assert!(msg.contains("/some/path"));
46    }
47}