Skip to main content

scala_chromatica/
error.rs

1//! Error types for colormap I/O operations
2
3use std::io;
4
5/// Error types for colormap operations
6#[derive(Debug)]
7pub enum ColorMapError {
8    /// I/O error (file read/write)
9    IoError(io::Error),
10    /// JSON parsing/serialization error
11    JsonError(serde_json::Error),
12    /// Colormap not found by name
13    NotFound(String),
14    /// Could not determine config directory
15    NoConfigDirectory,
16}
17
18impl std::fmt::Display for ColorMapError {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            ColorMapError::IoError(e) => write!(f, "I/O error: {}", e),
22            ColorMapError::JsonError(e) => write!(f, "JSON error: {}", e),
23            ColorMapError::NotFound(name) => write!(f, "ColorMap '{}' not found", name),
24            ColorMapError::NoConfigDirectory => write!(f, "Could not find config directory"),
25        }
26    }
27}
28
29impl std::error::Error for ColorMapError {}
30
31impl From<io::Error> for ColorMapError {
32    fn from(err: io::Error) -> Self {
33        ColorMapError::IoError(err)
34    }
35}
36
37impl From<serde_json::Error> for ColorMapError {
38    fn from(err: serde_json::Error) -> Self {
39        ColorMapError::JsonError(err)
40    }
41}
42
43/// Result type for colormap operations
44pub type Result<T> = std::result::Result<T, ColorMapError>;