Skip to main content

communitas_core/
error.rs

1// Central application error type for backend commands and services
2
3use thiserror::Error;
4
5#[allow(dead_code)]
6pub type AppResult<T> = Result<T, AppError>;
7
8#[allow(dead_code)]
9#[derive(Debug, Error)]
10pub enum AppError {
11    #[error("I/O error: {0}")]
12    Io(#[from] std::io::Error),
13
14    #[error("Serialization error: {0}")]
15    Serde(#[from] serde_json::Error),
16
17    #[error("Hex decode error: {0}")]
18    Hex(#[from] hex::FromHexError),
19
20    #[error("Mutex poisoned")]
21    MutexPoisoned,
22
23    #[error("Validation error: {0}")]
24    Validation(String),
25
26    #[error("Not found: {0}")]
27    NotFound(String),
28
29    #[error("Network error: {0}")]
30    Network(String),
31
32    #[error("Other: {0}")]
33    Other(String),
34}
35
36impl From<anyhow::Error> for AppError {
37    fn from(e: anyhow::Error) -> Self {
38        AppError::Other(e.to_string())
39    }
40}
41
42impl From<toml::de::Error> for AppError {
43    fn from(e: toml::de::Error) -> Self {
44        AppError::Other(format!("TOML error: {}", e))
45    }
46}