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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::{type_tag::TypeTag, Message};
use ctxerr::ctxerr;
use std::sync::Arc;

pub trait AbstractError: std::error::Error + Message {}
impl<T: std::error::Error + Message> AbstractError for T {}

#[derive(Clone)]
#[ctxerr]
pub enum ErrorKind {
    #[error("Internal Error: {0}")]
    InternalError(&'static str),

    #[error("No Such Receiver Error: MessageTypeQuery ({0:?}) -> {1:?}")]
    NoSuchReceiver(TypeTag, Option<TypeTag>),

    #[error("Already Initialized")]
    AlreadyInitialized,

    #[error("Dynamic Cast Failed: got ({0}), but expected({1})")]
    MessageDynamicCastFail(TypeTag, TypeTag),

    #[error("Try Send Fail Error")]
    TrySendError,

    #[error("MessageCell is empty, it expected to have message!")]
    EmptyMessageCellError,

    #[error("Send Fail")]
    SendError,

    #[error("Handler did not attached any result (it supposed to be send?)")]
    HandlerNoResultAttached,

    #[error("Wrong permit object")]
    WrongPermitObject,

    #[error("Trying to poll wrong task ({0})")]
    ErrorPollWrongTask(String),

    #[error("Marker indicats that producer finished producing.")]
    ProducerFinished,

    #[error("Bus is closed!")]
    BusClosed,

    #[error("Uninitialized")]
    Uninitialized,

    #[error("Handler Error: {0}")]
    HandlerError(Arc<dyn AbstractError>),
}

impl Clone for Error {
    fn clone(&self) -> Self {
        Self {
            kind: self.kind.clone(),
            backtrace: None,
            location: None,
        }
    }
}

pub trait IntoError {
    fn into_error(self) -> Error;
}

impl<T: AbstractError> IntoError for T {
    fn into_error(self) -> Error {
        ErrorKind::HandlerError(Arc::new(self)).into()
    }
}