anathema_runtime/
error.rs

1use std::error::Error as StdError;
2use std::fmt::{self, Display};
3
4use anathema_templates::error::Error as TemplateError;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug)]
9pub enum Error {
10    Template(TemplateError),
11    Notify(notify::Error),
12    Widget(anathema_widgets::error::Error),
13    Stop,
14    InvalidComponentName,
15}
16
17impl Display for Error {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            Error::Template(template) => write!(f, "{template}"),
21            Error::Stop => write!(f, "stopping"),
22            Error::Notify(err) => write!(f, "{err}"),
23            Error::Widget(err) => write!(f, "{err}"),
24            Error::InvalidComponentName => write!(f, "no such component"),
25        }
26    }
27}
28
29impl StdError for Error {}
30
31impl From<TemplateError> for Error {
32    fn from(err: TemplateError) -> Self {
33        Self::Template(err)
34    }
35}
36
37impl From<notify::Error> for Error {
38    fn from(err: notify::Error) -> Self {
39        Self::Notify(err)
40    }
41}
42
43impl From<anathema_widgets::error::Error> for Error {
44    fn from(value: anathema_widgets::error::Error) -> Self {
45        Self::Widget(value)
46    }
47}