1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7 NotFound(String),
8 InvalidInput(String),
9 Internal(anyhow::Error),
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Error::NotFound(msg) => write!(f, "Not found: {}", msg),
16 Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
17 Error::Internal(err) => write!(f, "Internal error: {}", err),
18 }
19 }
20}
21
22impl std::error::Error for Error {
23 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
24 match self {
25 Error::Internal(err) => Some(err.as_ref()),
26 _ => None,
27 }
28 }
29}
30
31impl From<anyhow::Error> for Error {
32 fn from(err: anyhow::Error) -> Self {
33 Error::Internal(err)
34 }
35}