use std::fmt;
use crate::Path;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Parse {
line: usize,
column: usize,
message: String,
},
Pointer {
pointer: String,
},
NoNode {
path: Path,
},
WrongKind {
path: Path,
expected: &'static str,
},
Repeated {
path: Path,
},
KeyExists {
path: Path,
},
Unsupported {
path: Path,
what: &'static str,
},
Invalid {
message: String,
},
#[cfg(feature = "serde")]
Serialize {
message: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parse {
line,
column,
message,
} => write!(formatter, "line {line}, column {column}: {message}"),
Self::Pointer { pointer } => write!(formatter, "{pointer:?} is not a JSON pointer"),
Self::NoNode { path } => write!(formatter, "no node at {path}"),
Self::WrongKind { path, expected } => {
write!(formatter, "the node at {path} is not {expected}")
}
Self::KeyExists { path } => write!(formatter, "{path} already exists"),
Self::Repeated { path } => write!(formatter, "{path} is named twice"),
Self::Unsupported { path, what } => write!(formatter, "at {path}: cannot {what} yet"),
Self::Invalid { message } => write!(formatter, "the edit would not parse: {message}"),
#[cfg(feature = "serde")]
Self::Serialize { message } => {
write!(formatter, "cannot serialize the value: {message}")
}
}
}
}
impl std::error::Error for Error {}