#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
PathNotFound,
InvalidJsonSyntax {
pos: usize,
msg: &'static str,
},
InvalidPath {
msg: &'static str,
},
IndexOutOfBounds {
index: usize,
},
TypeMismatch {
expected: &'static str,
found: &'static str,
},
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::PathNotFound => write!(f, "Path not found in JSON"),
Error::InvalidJsonSyntax { pos, msg } => {
write!(f, "Invalid JSON syntax at position {}: {}", pos, msg)
}
Error::InvalidPath { msg } => write!(f, "Invalid JSON path: {}", msg),
Error::IndexOutOfBounds { index } => {
write!(f, "Array index out of bounds: {}", index)
}
Error::TypeMismatch { expected, found } => {
write!(
f,
"Type mismatch: expected '{}', found '{}'",
expected, found
)
}
}
}
}
impl std::error::Error for Error {}