es_entity/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use thiserror::Error;

#[derive(Error, Debug)]
pub enum EsEntityError {
    #[error("EsEntityError - UninitializedFieldError: {0}")]
    UninitializedFieldError(#[from] derive_builder::UninitializedFieldError),
    #[error("EsEntityError - Deserialization: {0}")]
    EventDeserialization(#[from] serde_json::Error),
    #[error("EntityError - NotFound")]
    NotFound,
    #[error("EntityError - ConcurrentModification")]
    ConcurrentModification,
}

#[derive(Error, Debug)]
#[error("CursorDestructureError: couldn't turn {0} into {1}")]
pub struct CursorDestructureError(&'static str, &'static str);

impl From<(&'static str, &'static str)> for CursorDestructureError {
    fn from((name, variant): (&'static str, &'static str)) -> Self {
        Self(name, variant)
    }
}

#[derive(Error, Debug)]
pub enum EsRepoError {
    #[error("EsRepoError - Sqlx: {0}")]
    Sqlx(#[from] sqlx::Error),
    #[error("{0}")]
    EsEntityError(EsEntityError),
    #[error("{0}")]
    CursorDestructureError(#[from] CursorDestructureError),
}

crate::from_es_entity_error!(EsRepoError);