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: (usize, usize),
36 /// Actual dimensions (width, height).
37 actual: (usize, usize),
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 /// Quality metric is below the specified threshold.
67 #[error("{metric} quality below threshold: {value} (threshold: {threshold})")]
68 QualityBelowThreshold {
69 /// Name of the quality metric.
70 metric: String,
71 /// Actual value.
72 value: f64,
73 /// Threshold that was not met.
74 threshold: f64,
75 },
76
77 /// Unsupported image or codec format.
78 #[error("Unsupported format: {0}")]
79 UnsupportedFormat(String),
80
81 /// Error writing report files.
82 #[error("Report error: {0}")]
83 Report(String),
84
85 /// Cache-related error.
86 #[error("Cache error: {0}")]
87 Cache(String),
88
89 /// I/O error wrapper.
90 #[error(transparent)]
91 Io(#[from] std::io::Error),
92
93 /// JSON serialization/deserialization error.
94 #[error("JSON error: {0}")]
95 Json(#[from] serde_json::Error),
96
97 /// CSV error.
98 #[error("CSV error: {0}")]
99 Csv(#[from] csv::Error),
100}