hocr_parser/
error.rs

1use thiserror::Error;
2
3/// hOCR parsing error variants.
4#[derive(Error, Debug, Clone)]
5pub enum HOCRParserError {
6    /// Unknown hOCR element.
7    #[error("Unknown element found in hOCR file at {0}: elements either must be defined in the spec or start with 'ocrx_' prefix")]
8    UnknownElement(roxmltree::TextPos),
9    /// Unknown hOCR property.
10    #[error("Unknown property found in hOCR file at {0}: properties either must be defined in the spec or start with 'x_' prefix")]
11    UnknownProperty(roxmltree::TextPos),
12    /// Cannot construct hOCR element from node: it is not of type Element.
13    #[error("Cannot construct hOCR Element from node: it is not of type Element at {0}")]
14    NodeIsNotElement(roxmltree::TextPos),
15    /// No `<head>` element found in hOCR file.
16    #[error("No <head> element found in hOCR file")]
17    NoHeadElement,
18    /// No `<body>` element found in hOCR file.
19    #[error("No <body> element found in hOCR file")]
20    NoBodyElement,
21    /// No OCR system found in hOCR file metadata.
22    #[error("No OCR system found in hOCR file metadata; invalid hOCR according to spec")]
23    NoOCRSystem,
24    /// No OCR capabilities found in hOCR file metadata.
25    #[error("No OCR capabilities found in hOCR file metadata; invalid hOCR according to spec")]
26    NoOCRCapabilities,
27    /// XML parse error.
28    #[error("roxmltree error: {0}")]
29    XMLParseError(#[from] roxmltree::Error),
30}
31
32/// A `Result` type alias using `HOCRParserError` instances as the error variant.
33pub type Result<T, E = HOCRParserError> = std::result::Result<T, E>;