Skip to main content

oxipdf_html/
error.rs

1//! Error types for HTML → StyledTree conversion.
2
3/// Error produced during HTML → StyledTree conversion.
4#[derive(Debug)]
5pub enum HtmlError {
6    /// The HTML document has no renderable body content.
7    EmptyDocument,
8    /// A CSS value could not be parsed.
9    CssParseError { detail: String },
10    /// A `data:` URI could not be decoded.
11    DataUriError { detail: String },
12    /// The IR tree builder rejected the tree (validation failure).
13    TreeBuildError(oxipdf_ir::error::InputValidationError),
14}
15
16impl std::fmt::Display for HtmlError {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        match self {
19            Self::EmptyDocument => write!(f, "HTML document has no renderable content"),
20            Self::CssParseError { detail } => write!(f, "CSS parse error: {detail}"),
21            Self::DataUriError { detail } => write!(f, "data URI error: {detail}"),
22            Self::TreeBuildError(e) => write!(f, "tree build error: {e}"),
23        }
24    }
25}
26
27impl std::error::Error for HtmlError {}
28
29impl From<oxipdf_ir::error::InputValidationError> for HtmlError {
30    fn from(e: oxipdf_ir::error::InputValidationError) -> Self {
31        Self::TreeBuildError(e)
32    }
33}