1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/// Error returned by Lectito extraction and conversion functions.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// HTML parsing failed before extraction could start.
#[error("failed to parse HTML")]
HtmlParse,
/// The supplied base URL could not be parsed.
#[error("invalid base URL: {0}")]
InvalidBaseUrl(String),
/// The input exceeded `ReadabilityOptions::max_elems_to_parse`.
#[error("document has {actual} elements, exceeding max_elems_to_parse={limit}")]
MaxElemsExceeded {
/// Element count found in the document.
actual: usize,
/// Configured maximum element count.
limit: usize,
},
/// A site profile could not be parsed or converted into selectors.
#[error("invalid site profile {name}: {message}")]
InvalidSiteProfile {
/// Profile name or source label.
name: String,
/// Parse or validation message.
message: String,
},
/// Article HTML serialization failed after extraction.
#[error("failed to serialize article HTML")]
Serialization,
}
impl Error {
/// Creates an error for a site profile that could not be parsed or used.
///
/// `name` identifies the profile source and `message` describes the parse
/// or validation failure.
pub fn invalid_site_profile(name: impl ToString, message: impl ToString) -> Self {
Self::InvalidSiteProfile { name: name.to_string(), message: message.to_string() }
}
/// Creates an error for a document that exceeds an element-count limit.
///
/// `actual` is the number of elements found and `limit` is the configured
/// value from the `ReadabilityOptions::max_elems_to_parse` field.
pub fn max_elems_exceeded(actual: usize, limit: usize) -> Self {
Self::MaxElemsExceeded { actual, limit }
}
}
/// Result type used by Lectito APIs.
pub type Result<T> = std::result::Result<T, Error>;