1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 Parse(scheme_edit::ParseError),
6 NoChannelsForm,
7 ChannelNotFound(String),
8 MissingField { record: String, field: String },
9 Invalid { field: String, reason: String },
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Error::Parse(e) => write!(f, "parse error: {e}"),
16 Error::NoChannelsForm => write!(f, "no `list` / `cons*` / `cons` form found"),
17 Error::ChannelNotFound(name) => write!(f, "channel `{name}` not found"),
18 Error::MissingField { record, field } => write!(f, "{record}: missing {field}"),
19 Error::Invalid { field, reason } => write!(f, "invalid {field}: {reason}"),
20 }
21 }
22}
23
24impl std::error::Error for Error {
25 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26 match self {
27 Error::Parse(e) => Some(e),
28 _ => None,
29 }
30 }
31}
32
33impl From<scheme_edit::ParseError> for Error {
34 fn from(e: scheme_edit::ParseError) -> Self {
35 Error::Parse(e)
36 }
37}