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("Projection error: {0}")]
31    Projection(String),
32
33    #[error("Event decoding error: {0}")]
34    EventDecode(String),
35
36    #[error("Preflight validation error: {0}")]
37    PreflightFailed(String),
38
39    #[error("Lock error: {0}")]
40    Lock(String),
41
42    #[error("Not found: {0}")]
43    NotFound(String),
44
45    #[error("Invalid state: {0}")]
46    InvalidState(String),
47
48    #[error("Other error: {0}")]
49    Other(#[from] anyhow::Error),
50}
51
52pub type Result<T> = std::result::Result<T, AzothError>;
53
54// Custom Error Types:
55//
56// Azoth supports custom error types through the `#[from] anyhow::Error` variant.
57// Any error implementing `std::error::Error + Send + Sync + 'static` can be
58// converted to `AzothError::Other`.
59//
60// For better control, implement `From<YourError> for AzothError` directly.
61//
62// Example:
63//
64// use thiserror::Error;
65//
66// #[derive(Error, Debug)]
67// pub enum MyAppError {
68//     #[error("Business logic error: {0}")]
69//     BusinessLogic(String),
70//
71//     #[error("Authorization error: {0}")]
72//     Unauthorized(String),
73//
74//     #[error(transparent)]
75//     Azoth(#[from] AzothError),
76// }
77//
78// impl From<MyAppError> for AzothError {
79//     fn from(err: MyAppError) -> Self {
80//         match err {
81//             MyAppError::Azoth(e) => e,
82//             other => AzothError::Other(other.into()),
83//         }
84//     }
85// }