#[derive(Debug)]
pub enum Error {
Io(std::io::Error),
Json(serde_json::Error),
Invalid(String),
Busy(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(error) => write!(f, "local node I/O: {error}"),
Self::Json(error) => write!(f, "local node encoding: {error}"),
Self::Invalid(message) => f.write_str(message),
Self::Busy(message) => write!(f, "local node busy: {message}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(error) => Some(error),
Self::Json(error) => Some(error),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Self::Io(error)
}
}
impl From<serde_json::Error> for Error {
fn from(error: serde_json::Error) -> Self {
Self::Json(error)
}
}