Skip to main content

html_to_markdown_rs/
error.rs

1//! Error types for HTML to Markdown conversion.
2
3use thiserror::Error;
4
5/// Result type for conversion operations.
6pub type Result<T> = std::result::Result<T, ConversionError>;
7
8/// Errors that can occur during HTML to Markdown conversion.
9#[derive(Error, Debug)]
10pub enum ConversionError {
11    /// HTML parsing error
12    #[error("HTML parsing error: {0}")]
13    ParseError(String),
14
15    /// HTML sanitization error
16    #[error("Sanitization error: {0}")]
17    SanitizationError(String),
18
19    /// Invalid configuration
20    #[error("Invalid configuration: {0}")]
21    ConfigError(String),
22
23    /// I/O error — stores the error message string so the variant is FFI-safe.
24    ///
25    /// Use `ConversionError::from(io_error)` to convert from `std::io::Error`.
26    #[error("I/O error: {0}")]
27    IoError(String),
28
29    /// Panic caught during conversion to prevent unwinding across FFI boundaries
30    #[error("Internal panic: {0}")]
31    Panic(String),
32
33    /// Invalid input data
34    #[error("Invalid input: {0}")]
35    InvalidInput(String),
36
37    /// Visitor callback error
38    #[cfg(feature = "visitor")]
39    #[error("Visitor error: {0}")]
40    Visitor(String),
41
42    /// Generic conversion error
43    #[error("Conversion error: {0}")]
44    Other(String),
45}
46
47impl From<std::io::Error> for ConversionError {
48    fn from(error: std::io::Error) -> Self {
49        Self::IoError(error.to_string())
50    }
51}