Skip to main content

oximedia_subtitle/
error.rs

1//! Error types for subtitle processing.
2
3use thiserror::Error;
4
5/// Result type for subtitle operations.
6pub type SubtitleResult<T> = Result<T, SubtitleError>;
7
8/// Errors that can occur during subtitle processing.
9#[derive(Debug, Error)]
10pub enum SubtitleError {
11    /// Parse error.
12    #[error("Parse error: {0}")]
13    ParseError(String),
14
15    /// Invalid subtitle format.
16    #[error("Invalid subtitle format: {0}")]
17    InvalidFormat(String),
18
19    /// Invalid timestamp.
20    #[error("Invalid timestamp: {0}")]
21    InvalidTimestamp(String),
22
23    /// Font loading error.
24    #[error("Font loading error: {0}")]
25    FontError(String),
26
27    /// Text rendering error.
28    #[error("Text rendering error: {0}")]
29    RenderError(String),
30
31    /// Invalid color specification.
32    #[error("Invalid color: {0}")]
33    InvalidColor(String),
34
35    /// Invalid style parameter.
36    #[error("Invalid style: {0}")]
37    InvalidStyle(String),
38
39    /// Unsupported feature.
40    #[error("Unsupported feature: {0}")]
41    UnsupportedFeature(String),
42
43    /// I/O error.
44    #[error("I/O error: {0}")]
45    IoError(String),
46
47    /// Invalid frame format for overlay.
48    #[error("Invalid frame format: {0}")]
49    InvalidFrameFormat(String),
50
51    /// Internal error.
52    #[error("Internal error: {0}")]
53    Internal(String),
54}
55
56impl From<std::io::Error> for SubtitleError {
57    fn from(err: std::io::Error) -> Self {
58        Self::IoError(err.to_string())
59    }
60}
61
62impl From<std::string::FromUtf8Error> for SubtitleError {
63    fn from(err: std::string::FromUtf8Error) -> Self {
64        Self::ParseError(format!("UTF-8 decode error: {err}"))
65    }
66}