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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//! Closed connector and interpreter error families (safe diagnostics only).
use thiserror::Error;
/// High-level connector error classification.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ConnectorErrorKind {
/// Invalid open/config parameters.
ConfigurationInvalid,
/// Required dialect unavailable or ambiguous.
DialectUnavailable,
/// Credential reference could not be resolved (no secret material in error).
CredentialUnavailable,
/// Transport open/connect failed.
ConnectionFailed,
/// Write path failed.
WriteFailed,
/// Read path failed.
ReadFailed,
/// Remote closed the connection.
RemoteClosed,
/// Deadline exceeded.
DeadlineExceeded,
/// Cooperative cancellation.
Cancelled,
/// Forced termination.
Terminated,
/// Local resource (queue/task) failure or limit.
LocalResourceFailed,
/// Internal invariant broken.
InvariantViolation,
/// Session create/load/routing failure (profile-specific).
SessionFailed,
/// Protocol/JSON-RPC framing failure (bounded classification).
ProtocolFailed,
}
/// Connector error with safe, bounded diagnostics.
#[derive(Clone, Debug, Error, PartialEq, Eq)]
#[error("{kind:?}: {message}")]
pub struct ConnectorError {
/// Closed error family.
pub kind: ConnectorErrorKind,
/// Bounded human-safe message (no secrets).
pub message: String,
/// Optional connection correlation (may be absent during open failures).
pub connection_id: Option<String>,
}
impl ConnectorError {
/// Construct a typed error.
pub fn new(kind: ConnectorErrorKind, message: impl Into<String>) -> Self {
Self {
kind,
message: message.into(),
connection_id: None,
}
}
/// Attach a connection id for correlation (not a secret).
pub fn with_connection_id(mut self, id: impl Into<String>) -> Self {
self.connection_id = Some(id.into());
self
}
/// Configuration invalid.
pub fn configuration_invalid(message: impl Into<String>) -> Self {
Self::new(ConnectorErrorKind::ConfigurationInvalid, message)
}
/// Cancelled.
pub fn cancelled() -> Self {
Self::new(ConnectorErrorKind::Cancelled, "connection cancelled")
}
/// Terminated.
pub fn terminated() -> Self {
Self::new(ConnectorErrorKind::Terminated, "connection terminated")
}
/// Resource / bound exceeded.
pub fn resource(message: impl Into<String>) -> Self {
Self::new(ConnectorErrorKind::LocalResourceFailed, message)
}
/// Protocol failure.
pub fn protocol(message: impl Into<String>) -> Self {
Self::new(ConnectorErrorKind::ProtocolFailed, message)
}
/// Connection failed.
pub fn connection_failed(message: impl Into<String>) -> Self {
Self::new(ConnectorErrorKind::ConnectionFailed, message)
}
/// Session operation failed.
pub fn session_failed(message: impl Into<String>) -> Self {
Self::new(ConnectorErrorKind::SessionFailed, message)
}
}
/// Interpreter error classification.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum InterpreterErrorKind {
/// Unsupported dialect.
UnsupportedDialect,
/// Dialect binding mismatch.
DialectBindingMismatch,
/// Malformed frame.
MalformedFrame,
/// Frame/buffer limit exceeded.
FrameLimitExceeded,
/// Unsupported semantic event.
UnsupportedSemanticEvent,
/// Malformed semantic payload.
MalformedSemanticPayload,
/// Sentence assembly limit.
SentenceLimitExceeded,
/// Structure limit.
StructureLimitExceeded,
/// Tool identity missing/conflict.
ToolIdentityError,
/// Tool limit exceeded.
ToolLimitExceeded,
/// Output backpressure exceeded.
OutputBackpressureExceeded,
/// Connector ended unexpectedly.
ConnectorEndedUnexpectedly,
/// Cancelled.
Cancelled,
/// Invariant violation.
InvariantViolation,
/// Configuration invalid.
ConfigurationInvalid,
}
/// Interpreter error with safe diagnostics.
#[derive(Clone, Debug, Error, PartialEq, Eq)]
#[error("{kind:?}: {message}")]
pub struct InterpreterError {
/// Closed error family.
pub kind: InterpreterErrorKind,
/// Bounded safe message.
pub message: String,
}
impl InterpreterError {
/// Construct a typed error.
pub fn new(kind: InterpreterErrorKind, message: impl Into<String>) -> Self {
Self {
kind,
message: message.into(),
}
}
/// Unsupported dialect.
pub fn unsupported_dialect(message: impl Into<String>) -> Self {
Self::new(InterpreterErrorKind::UnsupportedDialect, message)
}
/// Malformed frame.
pub fn malformed_frame(message: impl Into<String>) -> Self {
Self::new(InterpreterErrorKind::MalformedFrame, message)
}
/// Limit exceeded.
pub fn limit(message: impl Into<String>) -> Self {
Self::new(InterpreterErrorKind::FrameLimitExceeded, message)
}
/// Cancelled.
pub fn cancelled() -> Self {
Self::new(InterpreterErrorKind::Cancelled, "interpretation cancelled")
}
/// Output backpressure.
pub fn backpressure() -> Self {
Self::new(
InterpreterErrorKind::OutputBackpressureExceeded,
"canonical output queue full",
)
}
}