Skip to main content

oximedia_conform/
error.rs

1//! Error types for oximedia-conform.
2
3use std::path::PathBuf;
4
5/// Result type for conform operations.
6pub type ConformResult<T> = Result<T, ConformError>;
7
8/// Errors that can occur during media conforming operations.
9#[derive(Debug, thiserror::Error)]
10pub enum ConformError {
11    /// I/O error.
12    #[error("I/O error: {0}")]
13    Io(#[from] std::io::Error),
14
15    /// EDL parsing error.
16    #[error("EDL error: {0}")]
17    Edl(String),
18
19    /// AAF parsing error.
20    #[error("AAF error: {0}")]
21    Aaf(String),
22
23    /// XML parsing error.
24    #[error("XML parsing error: {0}")]
25    Xml(#[from] quick_xml::Error),
26
27    /// Database error.
28    #[error("Database error: {0}")]
29    Database(String),
30
31    /// Missing source file.
32    #[error("Missing source file: {0}")]
33    MissingSource(PathBuf),
34
35    /// No matching source found for clip.
36    #[error("No matching source found for clip: {0}")]
37    NoMatch(String),
38
39    /// Ambiguous matches found.
40    #[error("Ambiguous matches found for clip {clip}: {count} candidates")]
41    AmbiguousMatch {
42        /// Clip identifier.
43        clip: String,
44        /// Number of matching candidates.
45        count: usize,
46    },
47
48    /// Invalid timecode.
49    #[error("Invalid timecode: {0}")]
50    InvalidTimecode(String),
51
52    /// Timecode mismatch.
53    #[error("Timecode mismatch: expected {expected}, found {found}")]
54    TimecodeMismatch {
55        /// Expected timecode.
56        expected: String,
57        /// Found timecode.
58        found: String,
59    },
60
61    /// Invalid frame rate.
62    #[error("Invalid frame rate: {0}")]
63    InvalidFrameRate(String),
64
65    /// Unsupported format.
66    #[error("Unsupported format: {0}")]
67    UnsupportedFormat(String),
68
69    /// Invalid configuration.
70    #[error("Invalid configuration: {0}")]
71    InvalidConfig(String),
72
73    /// Missing field.
74    #[error("Missing required field: {0}")]
75    MissingField(String),
76
77    /// Invalid range.
78    #[error("Invalid range: {0}")]
79    InvalidRange(String),
80
81    /// Export error.
82    #[error("Export error: {0}")]
83    Export(String),
84
85    /// Validation error.
86    #[error("Validation error: {0}")]
87    Validation(String),
88
89    /// Checksum mismatch.
90    #[error("Checksum mismatch for {path}: expected {expected}, found {found}")]
91    ChecksumMismatch {
92        /// The file path.
93        path: PathBuf,
94        /// Expected checksum.
95        expected: String,
96        /// Found checksum.
97        found: String,
98    },
99
100    /// Duration mismatch.
101    #[error("Duration mismatch for {path}: expected {expected}s, found {found}s")]
102    DurationMismatch {
103        /// The file path.
104        path: PathBuf,
105        /// Expected duration.
106        expected: f64,
107        /// Found duration.
108        found: f64,
109    },
110
111    /// Insufficient handles.
112    #[error("Insufficient handles for clip {clip}: need {needed} frames, have {available} frames")]
113    InsufficientHandles {
114        /// Clip identifier.
115        clip: String,
116        /// Needed frames.
117        needed: u64,
118        /// Available frames.
119        available: u64,
120    },
121
122    /// Session not found.
123    #[error("Session not found: {0}")]
124    SessionNotFound(String),
125
126    /// Async task error.
127    #[cfg(not(target_arch = "wasm32"))]
128    #[error("Async task error: {0}")]
129    TaskJoin(#[from] tokio::task::JoinError),
130
131    /// Serialization error.
132    #[error("Serialization error: {0}")]
133    Serialization(#[from] serde_json::Error),
134
135    /// Other error.
136    #[error("{0}")]
137    Other(String),
138}
139
140impl From<String> for ConformError {
141    fn from(s: String) -> Self {
142        Self::Other(s)
143    }
144}
145
146impl From<&str> for ConformError {
147    fn from(s: &str) -> Self {
148        Self::Other(s.to_string())
149    }
150}