1use serde::Serialize;
2use thiserror::Error;
3
4#[derive(Debug, Error, Serialize)]
5pub enum AppError {
6 #[error("I/O error: {0}")]
7 Io(String),
8 #[error("JSON serialization/deserialization error: {0}")]
9 Json(String),
10 #[error("Configuration error: {0}")]
11 Config(String),
12 #[error("Storage error: {0}")]
13 Storage(String),
14 #[error("An unexpected error occurred: {0}")]
15 Anyhow(String),
16}
17
18impl From<std::io::Error> for AppError {
19 fn from(err: std::io::Error) -> Self {
20 AppError::Io(err.to_string())
21 }
22}
23
24impl From<serde_json::Error> for AppError {
25 fn from(err: serde_json::Error) -> Self {
26 AppError::Json(err.to_string())
27 }
28}
29
30impl From<config::ConfigError> for AppError {
31 fn from(err: config::ConfigError) -> Self {
32 AppError::Config(err.to_string())
33 }
34}
35
36impl From<anyhow::Error> for AppError {
37 fn from(err: anyhow::Error) -> Self {
38 AppError::Anyhow(err.to_string())
39 }
40}