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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use thiserror::Error;
use uuid::Uuid;

// pub enum ErrorCriticality {
//     Recoverable,
//     RestartRequired,
//     Crash,
// }

// pub struct Error {
//     user_message: String,
//     debug_message: String,
//     criticality: ErrorCriticality,
// }

// impl Error {
//     pub fn new(user_message: String, debug_message: String, criticality: ErrorCriticality) -> Self {
//         Error {
//             user_message,
//             debug_message,
//             criticality,
//         }
//     }
// }

// // conversions

// impl From<zmq::Error> for Error {
//     fn from(e: zmq::Error) -> Self {
//         Error {
//             user_message: "Socket level error".to_string(),
//             debug_message: format!("Socket level error from ZMQ; details: {}", e),
//             criticality: ErrorCriticality::Recoverable,
//         }
//     }
// }

/// EngineError enumerates all possible error types returned by the event-engine framework.
#[derive(Error, Debug)]
pub enum EngineError {
    #[error("Engine could not create subscription socket")]
    SubSocketCreateError(#[from] zmq::Error),

    #[error("Engine could not bind subscription socket to TCP port {0}; details: {1}")]
    SubSocketTCPBindError(String, zmq::Error),

    #[error("Engine could not bind subscription socket to inproc URL {0}")]
    SubSocketInProcBindError(String),

    #[error("Engine could not bind publish socket to TCP port {0}")]
    PubSocketTCPBindError(String),

    #[error("Engine could not bind publish socket to inproc URL {0}")]
    PubSocketInProcBindError(String),

    #[error("Engine failed to establish publish socket for plugin: {0}")]
    PluginPubSocketError(Uuid),

    #[error("Engine failed to establish external socket for plugin: {0}; details: {1}")]
    PluginExternalSocketError(Uuid, zmq::Error),

    #[error("Engine failed to establish subscription socket for plugin: {0}")]
    PluginSubSocketError(Uuid),

    #[error("Engine failed to set subscription bytes filter for event name {0} for plugin: {1}:")]
    PluginSubscriptionError(String, Uuid),

    #[error("Engine failed to establish sync socket for plugin: {0}, port: {1}")]
    PluginSyncSocketError(Uuid, i32),

    #[error("Engine could not set the subscription filter on the socket.")]
    EngineSetSubFilterError(),

    #[error(
        "Engine could not set the 'all' wildcard filter for its incoming socket; details: {0}"
    )]
    EngineSetSubFilterAllError(zmq::Error),

    #[error("Plugin {0} failed to send the 'ready' sync message")]
    PluginSyncSendError(Uuid),

    #[error("Engine failed to create sync socket")]
    EngineSyncSocketCreateError(),

    #[error("Engine failed to bind to the sync socket on TCP port {0}; details: {1}")]
    EngineSyncSocketTCPBindError(i32, zmq::Error),

    #[error("Engine failed to bind to the sync socket to inproc URL {0}")]
    EngineSyncSocketInprocBindError(String),

    #[error("Engine failed to receive a message on the sync socket; details: {0}")]
    EngineSyncSocketMsgRcvError(zmq::Error),

    #[error("Engine failed to pop sync socket")]
    EngineSyncSocketPopError(),

    #[error("Engine failed to send a message on the sync socket; details: {0}")]
    EngineSyncSocketSendRcvError(zmq::Error),

    #[error("Engine failed to receive a message on the external socket; plugin id: {0}; details: {1}")]
    EngineExtSocketRcvError(Uuid, zmq::Error),

    #[error("Engine failed to receive a message on the sub socket for an external plugin; plugin id: {0}; details: {1}")]
    EngineExtSubSocketRcvError(Uuid, zmq::Error),

    #[error("Engine failed to send a message on the external socket for an external plugin; plugin id: {0}; details: {1}")]
    EngineExtSocketSendError(Uuid, zmq::Error),

    #[error("Engine failed to send a message on the pub socket for an external plugin; plugin id: {0}; details: {1}")]
    EngineExtPubSocketSendError(Uuid, zmq::Error),

}