monoloop_contracts/
error.rs1use thiserror::Error;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum ConnectorErrorKind {
8 ConfigurationInvalid,
10 DialectUnavailable,
12 CredentialUnavailable,
14 ConnectionFailed,
16 WriteFailed,
18 ReadFailed,
20 RemoteClosed,
22 DeadlineExceeded,
24 Cancelled,
26 Terminated,
28 LocalResourceFailed,
30 InvariantViolation,
32 SessionFailed,
34 ProtocolFailed,
36}
37
38#[derive(Clone, Debug, Error, PartialEq, Eq)]
40#[error("{kind:?}: {message}")]
41pub struct ConnectorError {
42 pub kind: ConnectorErrorKind,
44 pub message: String,
46 pub connection_id: Option<String>,
48}
49
50impl ConnectorError {
51 pub fn new(kind: ConnectorErrorKind, message: impl Into<String>) -> Self {
53 Self {
54 kind,
55 message: message.into(),
56 connection_id: None,
57 }
58 }
59
60 pub fn with_connection_id(mut self, id: impl Into<String>) -> Self {
62 self.connection_id = Some(id.into());
63 self
64 }
65
66 pub fn configuration_invalid(message: impl Into<String>) -> Self {
68 Self::new(ConnectorErrorKind::ConfigurationInvalid, message)
69 }
70
71 pub fn cancelled() -> Self {
73 Self::new(ConnectorErrorKind::Cancelled, "connection cancelled")
74 }
75
76 pub fn terminated() -> Self {
78 Self::new(ConnectorErrorKind::Terminated, "connection terminated")
79 }
80
81 pub fn resource(message: impl Into<String>) -> Self {
83 Self::new(ConnectorErrorKind::LocalResourceFailed, message)
84 }
85
86 pub fn protocol(message: impl Into<String>) -> Self {
88 Self::new(ConnectorErrorKind::ProtocolFailed, message)
89 }
90
91 pub fn connection_failed(message: impl Into<String>) -> Self {
93 Self::new(ConnectorErrorKind::ConnectionFailed, message)
94 }
95
96 pub fn session_failed(message: impl Into<String>) -> Self {
98 Self::new(ConnectorErrorKind::SessionFailed, message)
99 }
100}
101
102#[derive(Clone, Copy, Debug, PartialEq, Eq)]
104pub enum InterpreterErrorKind {
105 UnsupportedDialect,
107 DialectBindingMismatch,
109 MalformedFrame,
111 FrameLimitExceeded,
113 UnsupportedSemanticEvent,
115 MalformedSemanticPayload,
117 SentenceLimitExceeded,
119 StructureLimitExceeded,
121 ToolIdentityError,
123 ToolLimitExceeded,
125 OutputBackpressureExceeded,
127 ConnectorEndedUnexpectedly,
129 Cancelled,
131 InvariantViolation,
133 ConfigurationInvalid,
135}
136
137#[derive(Clone, Debug, Error, PartialEq, Eq)]
139#[error("{kind:?}: {message}")]
140pub struct InterpreterError {
141 pub kind: InterpreterErrorKind,
143 pub message: String,
145}
146
147impl InterpreterError {
148 pub fn new(kind: InterpreterErrorKind, message: impl Into<String>) -> Self {
150 Self {
151 kind,
152 message: message.into(),
153 }
154 }
155
156 pub fn unsupported_dialect(message: impl Into<String>) -> Self {
158 Self::new(InterpreterErrorKind::UnsupportedDialect, message)
159 }
160
161 pub fn malformed_frame(message: impl Into<String>) -> Self {
163 Self::new(InterpreterErrorKind::MalformedFrame, message)
164 }
165
166 pub fn limit(message: impl Into<String>) -> Self {
168 Self::new(InterpreterErrorKind::FrameLimitExceeded, message)
169 }
170
171 pub fn cancelled() -> Self {
173 Self::new(InterpreterErrorKind::Cancelled, "interpretation cancelled")
174 }
175
176 pub fn backpressure() -> Self {
178 Self::new(
179 InterpreterErrorKind::OutputBackpressureExceeded,
180 "canonical output queue full",
181 )
182 }
183}