1#[derive(Debug, thiserror::Error)]
3pub enum ParseError {
4 #[error("unexpected byte 0x{byte:02X} at offset {offset}")]
6 UnexpectedByte {
7 byte: u8,
9 offset: usize,
11 },
12
13 #[error("unexpected end of input at offset {offset}, state: {state}")]
15 UnexpectedEof {
16 offset: usize,
18 state: &'static str,
20 },
21
22 #[error("nesting depth limit exceeded ({depth} > {limit})")]
24 NestingTooDeep {
25 depth: u32,
27 limit: u32,
29 },
30}
31
32#[derive(Debug, thiserror::Error)]
34pub enum SelectorError {
35 #[error("invalid selector: {reason}")]
37 Invalid {
38 reason: String,
40 },
41}
42
43#[derive(Debug, thiserror::Error)]
45pub enum XPathError {
46 #[error("invalid xpath: {reason}")]
48 Invalid {
49 reason: String,
51 },
52}
53
54#[derive(Debug, thiserror::Error)]
56pub enum EncodingError {
57 #[error("decode error: malformed {encoding} input at byte offset {offset}")]
59 MalformedInput {
60 encoding: &'static str,
62 offset: usize,
64 },
65}
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn parse_error_display() {
73 let err = ParseError::UnexpectedByte {
74 byte: 0xFF,
75 offset: 42,
76 };
77 assert_eq!(err.to_string(), "unexpected byte 0xFF at offset 42");
78 }
79
80 #[test]
81 fn selector_error_display() {
82 let err = SelectorError::Invalid {
83 reason: "unclosed bracket".to_string(),
84 };
85 assert_eq!(err.to_string(), "invalid selector: unclosed bracket");
86 }
87
88 #[test]
89 fn xpath_error_display() {
90 let err = XPathError::Invalid {
91 reason: "unexpected token".to_string(),
92 };
93 assert_eq!(err.to_string(), "invalid xpath: unexpected token");
94 }
95
96 #[test]
97 fn encoding_error_display() {
98 let err = EncodingError::MalformedInput {
99 encoding: "windows-1252",
100 offset: 42,
101 };
102 assert_eq!(
103 err.to_string(),
104 "decode error: malformed windows-1252 input at byte offset 42"
105 );
106 }
107
108 #[test]
109 fn nesting_error_display() {
110 let err = ParseError::NestingTooDeep {
111 depth: 513,
112 limit: 512,
113 };
114 assert_eq!(err.to_string(), "nesting depth limit exceeded (513 > 512)");
115 }
116}