feed_parser/parsers/errors.rs
1use thiserror::Error;
2
3/// Errors that can occur while parsing a feed.
4///
5/// This enum is `#[non_exhaustive]`: new variants may be added in future minor
6/// releases, so downstream `match` expressions must include a wildcard arm.
7#[derive(Error, Debug)]
8#[non_exhaustive]
9pub enum ParseError {
10 /// The input is not well-formed XML.
11 #[error("Failed to parse XML: {0}")]
12 XmlParseError(#[from] quick_xml::Error),
13
14 /// An entry was well-formed XML but could not be turned into a [`Feed`].
15 ///
16 /// [`Feed`]: crate::parsers::Feed
17 #[error("Failed to deserialize feed entry: {0}")]
18 DeserializeError(#[from] quick_xml::DeError),
19
20 /// The input contained a byte sequence that is not valid UTF-8.
21 #[error("Feed contains invalid UTF-8: {0}")]
22 Utf8Error(#[from] std::str::Utf8Error),
23
24 /// Writing the normalized intermediate XML failed.
25 #[error("Failed to write intermediate XML: {0}")]
26 IoError(#[from] std::io::Error),
27
28 /// The document is valid XML but not a valid feed (e.g. an unclosed entry).
29 #[error("Invalid feed format: {0}")]
30 InvalidFeedFormat(String),
31
32 /// An entry is missing a field that [`Feed`] requires.
33 ///
34 /// [`Feed`]: crate::parsers::Feed
35 #[error("Missing required field: {0}")]
36 MissingField(String),
37}
38
39/// A [`Result`] alias whose error type is [`ParseError`].
40pub type ParseResult<T> = Result<T, ParseError>;