1use std::{error::Error, fmt::Display};
2
3use peekmore::PeekMoreError;
4
5pub type JsonPathResult<T> = Result<T, JsonPathError>;
6
7#[derive(Debug, PartialEq)]
8pub enum JsonPathError {
9 InvalidJsonPath(String, usize),
10 EvaluationError(String),
11}
12
13impl Error for JsonPathError {}
14
15impl Display for JsonPathError {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 match self {
18 JsonPathError::InvalidJsonPath(e, pos) => {
19 f.write_fmt(format_args!("Invalid JsonPath: {} at {}", e, pos))
20 }
21 JsonPathError::EvaluationError(e) => {
22 f.write_fmt(format_args!("JsonPath evaluation error: {}", e))
23 }
24 }
25 }
26}
27
28impl From<PeekMoreError> for JsonPathError {
29 fn from(_value: PeekMoreError) -> Self {
30 JsonPathError::InvalidJsonPath("Unexpected token".to_string(), 0)
31 }
32}