scrape_core/parser/
error.rs1use thiserror::Error;
4
5pub type ParseResult<T> = Result<T, ParseError>;
7
8#[derive(Debug, Error)]
10pub enum ParseError {
11 #[error("maximum nesting depth of {max_depth} exceeded")]
13 MaxDepthExceeded {
14 max_depth: usize,
16 },
17
18 #[error("empty or whitespace-only input")]
20 EmptyInput,
21
22 #[error("encoding error: {message}")]
24 EncodingError {
25 message: String,
27 },
28
29 #[error("internal parser error: {0}")]
31 InternalError(String),
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn test_max_depth_exceeded_display() {
40 let err = ParseError::MaxDepthExceeded { max_depth: 512 };
41 assert_eq!(err.to_string(), "maximum nesting depth of 512 exceeded");
42 }
43
44 #[test]
45 fn test_empty_input_display() {
46 let err = ParseError::EmptyInput;
47 assert_eq!(err.to_string(), "empty or whitespace-only input");
48 }
49
50 #[test]
51 fn test_encoding_error_display() {
52 let err = ParseError::EncodingError { message: "invalid UTF-8 sequence".into() };
53 assert_eq!(err.to_string(), "encoding error: invalid UTF-8 sequence");
54 }
55
56 #[test]
57 fn test_internal_error_display() {
58 let err = ParseError::InternalError("unexpected state".into());
59 assert_eq!(err.to_string(), "internal parser error: unexpected state");
60 }
61}