1use std::ops::Range;
3
4use quick_xml::escape::EscapeError as QuickXMLEscapeError;
5
6#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9#[allow(clippy::module_name_repetitions)]
10pub enum EscapeError
11{
12 #[error(
14 "Error while escaping character at range {0:?}: Null character entity not allowed"
15 )]
16 EntityWithNull(Range<usize>),
17
18 #[error(
20 "Error while escaping character at range {0:?}: Unrecognized escape symbol: {1:?}"
21 )]
22 UnrecognizedSymbol(Range<usize>, String),
23
24 #[error("Error while escaping character at range {0:?}: Cannot find ';' after '&'")]
26 UnterminatedEntity(Range<usize>),
27
28 #[error("Hexadecimal value is too long to convert to UTF-8")]
30 TooLongHexadecimal,
31
32 #[error("{0}' is not a valid hexadecimal character")]
34 InvalidHexadecimal(char),
35
36 #[error("Decimal value is too long to convert to UTF-8")]
38 TooLongDecimal,
39
40 #[error("'{0}' is not a valid decimal character")]
42 InvalidDecimal(char),
43
44 #[error("'{0}' is not a valid codepoint")]
46 InvalidCodepoint(u32),
47}
48
49impl EscapeError
50{
51 pub(crate) fn from_quick_xml(err: QuickXMLEscapeError) -> Self
52 {
53 match err {
54 QuickXMLEscapeError::EntityWithNull(range) => Self::EntityWithNull(range),
55 QuickXMLEscapeError::UnrecognizedSymbol(range, symbol) => {
56 Self::UnrecognizedSymbol(range, symbol)
57 }
58 QuickXMLEscapeError::UnterminatedEntity(range) => {
59 Self::UnterminatedEntity(range)
60 }
61 QuickXMLEscapeError::TooLongHexadecimal => Self::TooLongHexadecimal,
62 QuickXMLEscapeError::InvalidHexadecimal(character) => {
63 Self::InvalidHexadecimal(character)
64 }
65 QuickXMLEscapeError::TooLongDecimal => Self::TooLongDecimal,
66 QuickXMLEscapeError::InvalidDecimal(character) => {
67 Self::InvalidDecimal(character)
68 }
69 QuickXMLEscapeError::InvalidCodepoint(codepoint) => {
70 Self::InvalidCodepoint(codepoint)
71 }
72 }
73 }
74}