Skip to main content

ttml_subtitle/
error.rs

1//! Error types for ttml-subtitle.
2
3extern crate alloc;
4
5use alloc::string::String;
6use thiserror::Error;
7
8/// Result type alias for ttml-subtitle operations.
9pub type Result<T> = core::result::Result<T, Error>;
10
11/// Errors that can occur during TTML/IMSC processing.
12#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum Error {
15    /// XML parsing failed (syntax error, not well-formed).
16    #[error("XML parse error: {0}")]
17    XmlParse(String),
18
19    /// The root element is not `<tt>` in the TTML namespace.
20    #[error("expected root element <tt> in namespace http://www.w3.org/ns/ttml, got {0}")]
21    NotTtmlRoot(String),
22
23    /// A required element is missing.
24    #[error("missing required element: {0}")]
25    MissingElement(&'static str),
26
27    /// A required attribute is missing.
28    #[error("missing required attribute '{attr}' on element '{element}'")]
29    MissingAttribute {
30        /// The element name.
31        element: &'static str,
32        /// The attribute name.
33        attr: &'static str,
34    },
35
36    /// A required attribute value is malformed.
37    #[error("invalid value for attribute '{attr}' on element '{element}': {reason}")]
38    InvalidAttribute {
39        /// The element name.
40        element: &'static str,
41        /// The attribute name.
42        attr: &'static str,
43        /// Why the value is invalid.
44        reason: String,
45    },
46
47    /// A `time-expression` could not be parsed.
48    #[error("invalid time expression '{value}': {reason}")]
49    InvalidTimeExpression {
50        /// The raw time expression text.
51        value: String,
52        /// Why it's invalid.
53        reason: String,
54    },
55
56    /// IMSC profile validation failed.
57    #[error("IMSC validation error: {0}")]
58    Validation(String),
59
60    /// An unexpected element was found in a location where it is not valid.
61    #[error("unexpected element '{name}' in namespace '{ns}'")]
62    UnexpectedElement {
63        /// The element local name.
64        name: String,
65        /// The element namespace, if any.
66        ns: String,
67    },
68
69    /// An element was found that is prohibited by the content profile.
70    #[error("prohibited element '{name}' for the claimed profile")]
71    ProhibitedElement {
72        /// The element name.
73        name: String,
74    },
75
76    /// An attribute was found that is prohibited by the content profile.
77    #[error("prohibited attribute '{attr}' for the claimed profile")]
78    ProhibitedAttribute {
79        /// The attribute name.
80        attr: String,
81    },
82
83    /// A generic constraint violation.
84    #[error("{constraint}: {detail}")]
85    ConstraintViolation {
86        /// The constraint that was violated.
87        constraint: String,
88        /// Additional detail.
89        detail: String,
90    },
91
92    /// Serialization error.
93    #[error("serialization error: {0}")]
94    Serialize(String),
95}