Skip to main content

azoth_core/
error.rs

1use std::io;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum AzothError {
6    #[error("IO error: {0}")]
7    Io(#[from] io::Error),
8
9    #[error("Serialization error: {0}")]
10    Serialization(String),
11
12    #[error("Transaction error: {0}")]
13    Transaction(String),
14
15    #[error("Store is sealed at event {0}")]
16    Sealed(u64),
17
18    #[error("Store is paused, ingestion suspended")]
19    Paused,
20
21    #[error("Configuration error: {0}")]
22    Config(String),
23
24    #[error("Backup error: {0}")]
25    Backup(String),
26
27    #[error("Restore error: {0}")]
28    Restore(String),
29
30    #[error("Encryption error: {0}")]
31    Encryption(String),
32
33    #[error("Projection error: {0}")]
34    Projection(String),
35
36    #[error("Event decoding error: {0}")]
37    EventDecode(String),
38
39    #[error("Preflight validation error: {0}")]
40    PreflightFailed(String),
41
42    #[error("Lock error: {0}")]
43    Lock(String),
44
45    #[error("Not found: {0}")]
46    NotFound(String),
47
48    #[error("Invalid state: {0}")]
49    InvalidState(String),
50
51    #[error("Timeout: {0}")]
52    Timeout(String),
53
54    #[error("Circuit breaker is open, rejecting request")]
55    CircuitBreakerOpen,
56
57    #[error("Internal error: {0}")]
58    Internal(String),
59
60    #[error("Other error: {0}")]
61    Other(#[from] anyhow::Error),
62}
63
64pub type Result<T> = std::result::Result<T, AzothError>;
65
66// Custom Error Types:
67//
68// Azoth supports custom error types through the `#[from] anyhow::Error` variant.
69// Any error implementing `std::error::Error + Send + Sync + 'static` can be
70// converted to `AzothError::Other`.
71//
72// For better control, implement `From<YourError> for AzothError` directly.
73//
74// Example:
75//
76// use thiserror::Error;
77//
78// #[derive(Error, Debug)]
79// pub enum MyAppError {
80//     #[error("Business logic error: {0}")]
81//     BusinessLogic(String),
82//
83//     #[error("Authorization error: {0}")]
84//     Unauthorized(String),
85//
86//     #[error(transparent)]
87//     Azoth(#[from] AzothError),
88// }
89//
90// impl From<MyAppError> for AzothError {
91//     fn from(err: MyAppError) -> Self {
92//         match err {
93//             MyAppError::Azoth(e) => e,
94//             other => AzothError::Other(other.into()),
95//         }
96//     }
97// }