use std::fmt;
#[derive(Debug)]
pub enum Error {
Parse(scheme_edit::ParseError),
NoChannelsForm,
ChannelNotFound(String),
MissingField { record: String, field: String },
Invalid { field: String, reason: String },
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Parse(e) => write!(f, "parse error: {e}"),
Error::NoChannelsForm => write!(f, "no `list` / `cons*` / `cons` form found"),
Error::ChannelNotFound(name) => write!(f, "channel `{name}` not found"),
Error::MissingField { record, field } => write!(f, "{record}: missing {field}"),
Error::Invalid { field, reason } => write!(f, "invalid {field}: {reason}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Parse(e) => Some(e),
_ => None,
}
}
}
impl From<scheme_edit::ParseError> for Error {
fn from(e: scheme_edit::ParseError) -> Self {
Error::Parse(e)
}
}