1use std::io::{self, ErrorKind};
2use thiserror::Error;
3
4#[derive(Error, Debug)]
6pub enum AppError {
7 #[error("{0} component not exists")]
9 ComponentNotExist(&'static str),
10
11 #[error(transparent)]
13 EnvError(#[from] dotenvy::Error),
14
15 #[error(transparent)]
17 IOError(#[from] io::Error),
18
19 #[error(transparent)]
21 TomlParseError(#[from] toml::de::Error),
22
23 #[error("merge toml error: {0}")]
25 TomlMergeError(String),
26
27 #[error(transparent)]
29 JoinError(#[from] tokio::task::JoinError),
30
31 #[error("Failed to deserialize the configuration of prefix \"{0}\": {1}")]
33 DeserializeErr(&'static str, toml::de::Error),
34
35 #[error(transparent)]
37 OtherError(#[from] anyhow::Error),
38}
39
40impl AppError {
41 pub fn from_io(kind: ErrorKind, msg: &str) -> Self {
43 AppError::IOError(io::Error::new(kind, msg))
44 }
45}
46
47pub type Result<T> = std::result::Result<T, AppError>;