codec_eval/
error.rs

1//! Error types for codec-eval operations.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Result type alias for codec-eval operations.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Errors that can occur during codec evaluation.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// Failed to load an image file.
14    #[error("Image load failed: {path}: {reason}")]
15    ImageLoad {
16        /// Path to the image that failed to load.
17        path: PathBuf,
18        /// Reason for the failure.
19        reason: String,
20    },
21
22    /// Error from a codec during encoding or decoding.
23    #[error("Codec error ({codec}): {message}")]
24    Codec {
25        /// Codec identifier.
26        codec: String,
27        /// Error message from the codec.
28        message: String,
29    },
30
31    /// Image dimensions don't match between reference and test images.
32    #[error("Dimension mismatch: expected {expected:?}, got {actual:?}")]
33    DimensionMismatch {
34        /// Expected dimensions (width, height).
35        expected: (u32, u32),
36        /// Actual dimensions (width, height).
37        actual: (u32, u32),
38    },
39
40    /// Failed to calculate a quality metric.
41    #[error("Metric calculation failed: {metric}: {reason}")]
42    MetricCalculation {
43        /// Name of the metric that failed.
44        metric: String,
45        /// Reason for the failure.
46        reason: String,
47    },
48
49    /// Error in corpus management.
50    #[error("Corpus error: {0}")]
51    Corpus(String),
52
53    /// Error importing CSV data.
54    #[error("CSV import error at line {line}: {reason}")]
55    CsvImport {
56        /// Line number where the error occurred.
57        line: usize,
58        /// Reason for the failure.
59        reason: String,
60    },
61
62    /// Invalid quality value provided.
63    #[error("Invalid quality value: {0} (expected 0.0-100.0 or codec-specific range)")]
64    InvalidQuality(f64),
65
66    /// Unsupported image or codec format.
67    #[error("Unsupported format: {0}")]
68    UnsupportedFormat(String),
69
70    /// Error writing report files.
71    #[error("Report error: {0}")]
72    Report(String),
73
74    /// Cache-related error.
75    #[error("Cache error: {0}")]
76    Cache(String),
77
78    /// I/O error wrapper.
79    #[error(transparent)]
80    Io(#[from] std::io::Error),
81
82    /// JSON serialization/deserialization error.
83    #[error("JSON error: {0}")]
84    Json(#[from] serde_json::Error),
85
86    /// CSV error.
87    #[error("CSV error: {0}")]
88    Csv(#[from] csv::Error),
89}