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    Resolver(anathema_value_resolver::Error),
16}
17
18impl Display for Error {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            Error::Template(template) => write!(f, "{template}"),
22            Error::Stop => write!(f, "stopping"),
23            Error::Notify(err) => write!(f, "{err}"),
24            Error::Widget(err) => write!(f, "{err}"),
25            Error::Resolver(err) => write!(f, "{err}"),
26            Error::InvalidComponentName => write!(f, "no such component"),
27        }
28    }
29}
30
31impl StdError for Error {}
32
33impl From<TemplateError> for Error {
34    fn from(err: TemplateError) -> Self {
35        Self::Template(err)
36    }
37}
38
39impl From<notify::Error> for Error {
40    fn from(err: notify::Error) -> Self {
41        Self::Notify(err)
42    }
43}
44
45impl From<anathema_widgets::error::Error> for Error {
46    fn from(value: anathema_widgets::error::Error) -> Self {
47        Self::Widget(value)
48    }
49}
50
51impl From<anathema_value_resolver::Error> for Error {
52    fn from(value: anathema_value_resolver::Error) -> Self {
53        Self::Resolver(value)
54    }
55}