1use super::ErrorKind;
4use super::definition::ErrorCodeDefinition;
5use super::definition::drains;
6use super::definition::fatal;
7use super::definition::preempted;
8
9pub const SESSION_NOT_LOADED_CODE: i64 = -32024;
12
13pub const SESSION_STREAM_MISMATCH_CODE: i64 = -32025;
17
18pub const LIMITS_ABOVE_MAX_CODE: i64 = -32028;
22
23pub const DAEMON_DRAINING_CODE: i64 = -32039;
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38#[non_exhaustive]
39pub enum ErrorCode {
40 ParseError,
42 InvalidRequest,
44 MethodNotFound,
46 InvalidParams,
48 Internal,
50 Overloaded,
52 InputTooLarge,
54 CapabilityRequired,
56 NotFound,
58 Interrupted,
60 Cancelled,
62 SessionNotFound,
64 SessionInUse,
66 SessionAmbiguous,
68 ForkBoundaryInvalid,
70 SessionNotLoaded,
72 SessionStreamMismatch,
75 DaemonDraining,
79 LimitsAboveMax,
82 WorkspaceNotTrusted,
84 CommandRejected,
86 Backpressured,
88 SkillNotFound,
91 ComputerUseUnavailable,
93 MarketplaceNotFound,
95 PluginNotFound,
97 MarketplaceAlreadyExists,
99 PluginMutationsDisabled,
101 UploadNotFound,
104 ViewTruncated,
106 OutputUnavailable,
110 Boundary,
112 ApprovalNotFound,
114 ApprovalAlreadyResolved,
116 ApprovalChoiceInvalid,
118 ApprovalRequirementStale,
120 ApprovalReviewerUnavailable,
122 UserInputNotFound,
124 UserInputAlreadySettled,
126 UserInputAnswerInvalid,
128 MissingAnchor,
130 PrunedPrefix,
132 WrongStream,
134 UnknownStream,
136 UnknownProjection,
138 AdmissionNotFound,
140 AdmissionAlreadyResolved,
142 AdmissionChoiceInvalid,
144 UsageRefreshRateLimited,
146 UsageRefreshUnavailable,
148 UsageRefreshFailed,
150}
151
152impl ErrorCode {
153 pub const ALL: [Self; 51] = [
158 Self::ParseError,
159 Self::InvalidRequest,
160 Self::MethodNotFound,
161 Self::InvalidParams,
162 Self::Internal,
163 Self::Overloaded,
164 Self::InputTooLarge,
165 Self::CapabilityRequired,
166 Self::NotFound,
167 Self::Interrupted,
168 Self::Cancelled,
169 Self::SessionNotFound,
170 Self::SessionInUse,
171 Self::SessionAmbiguous,
172 Self::ForkBoundaryInvalid,
173 Self::SessionNotLoaded,
174 Self::SessionStreamMismatch,
175 Self::DaemonDraining,
176 Self::LimitsAboveMax,
177 Self::WorkspaceNotTrusted,
178 Self::CommandRejected,
179 Self::Backpressured,
180 Self::SkillNotFound,
181 Self::ComputerUseUnavailable,
182 Self::MarketplaceNotFound,
183 Self::PluginNotFound,
184 Self::MarketplaceAlreadyExists,
185 Self::PluginMutationsDisabled,
186 Self::UploadNotFound,
187 Self::ViewTruncated,
188 Self::OutputUnavailable,
189 Self::Boundary,
190 Self::ApprovalNotFound,
191 Self::ApprovalAlreadyResolved,
192 Self::ApprovalChoiceInvalid,
193 Self::ApprovalRequirementStale,
194 Self::ApprovalReviewerUnavailable,
195 Self::UserInputNotFound,
196 Self::UserInputAlreadySettled,
197 Self::UserInputAnswerInvalid,
198 Self::MissingAnchor,
199 Self::PrunedPrefix,
200 Self::WrongStream,
201 Self::UnknownStream,
202 Self::UnknownProjection,
203 Self::AdmissionNotFound,
204 Self::AdmissionAlreadyResolved,
205 Self::AdmissionChoiceInvalid,
206 Self::UsageRefreshRateLimited,
207 Self::UsageRefreshUnavailable,
208 Self::UsageRefreshFailed,
209 ];
210
211 const fn definition(self) -> ErrorCodeDefinition {
218 match self {
219 Self::ParseError => fatal(-32700, ErrorKind::ParseError),
220 Self::InvalidRequest => ErrorCodeDefinition::new(
221 -32600,
222 ErrorKind::InvalidRequest,
223 &[ErrorKind::NotInitialized, ErrorKind::AlreadyInitialized],
224 Some(false),
225 ),
226 Self::MethodNotFound => ErrorCodeDefinition::new(
227 -32601,
228 ErrorKind::MethodNotFound,
229 &[ErrorKind::ExperimentalRequired],
230 Some(false),
231 ),
232 Self::InvalidParams => ErrorCodeDefinition::new(
233 -32602,
234 ErrorKind::InvalidParams,
235 &[ErrorKind::ExperimentalRequired],
236 Some(false),
237 ),
238 Self::Internal => ErrorCodeDefinition::new(
239 -32603,
240 ErrorKind::Internal,
241 &[
242 ErrorKind::PageEventTooLarge,
243 ErrorKind::OutputResultTooLarge,
244 ],
245 Some(false),
246 ),
247 Self::Overloaded => drains(-32001, ErrorKind::Overloaded),
248 Self::InputTooLarge => fatal(-32002, ErrorKind::InputTooLarge),
249 Self::CapabilityRequired => fatal(-32010, ErrorKind::CapabilityRequired),
250 Self::NotFound => fatal(-32011, ErrorKind::NotFound),
251 Self::Interrupted => preempted(-32013, ErrorKind::Interrupted),
252 Self::Cancelled => preempted(-32014, ErrorKind::Cancelled),
253 Self::SessionNotFound => fatal(-32020, ErrorKind::SessionNotFound),
254 Self::SessionInUse => fatal(-32021, ErrorKind::SessionInUse),
255 Self::SessionAmbiguous => fatal(-32022, ErrorKind::SessionAmbiguous),
256 Self::ForkBoundaryInvalid => fatal(-32023, ErrorKind::ForkBoundaryInvalid),
257 Self::SessionNotLoaded => fatal(SESSION_NOT_LOADED_CODE, ErrorKind::SessionNotLoaded),
258 Self::SessionStreamMismatch => fatal(
259 SESSION_STREAM_MISMATCH_CODE,
260 ErrorKind::SessionStreamMismatch,
261 ),
262 Self::DaemonDraining => ErrorCodeDefinition::experimental_with_retry(
263 DAEMON_DRAINING_CODE,
264 ErrorKind::DaemonDraining,
265 Some(true),
266 ),
267 Self::LimitsAboveMax => {
268 ErrorCodeDefinition::experimental(LIMITS_ABOVE_MAX_CODE, ErrorKind::LimitsAboveMax)
269 }
270 Self::WorkspaceNotTrusted => {
271 ErrorCodeDefinition::experimental(-32029, ErrorKind::WorkspaceNotTrusted)
272 }
273 Self::CommandRejected => fatal(-32030, ErrorKind::CommandRejected),
274 Self::Backpressured => drains(-32031, ErrorKind::Backpressured),
275 Self::SkillNotFound => fatal(-32032, ErrorKind::SkillNotFound),
276 Self::ComputerUseUnavailable => fatal(-32033, ErrorKind::ComputerUseUnavailable),
277 Self::MarketplaceNotFound => fatal(-32034, ErrorKind::MarketplaceNotFound),
278 Self::PluginNotFound => fatal(-32035, ErrorKind::PluginNotFound),
279 Self::MarketplaceAlreadyExists => fatal(-32036, ErrorKind::MarketplaceAlreadyExists),
280 Self::PluginMutationsDisabled => fatal(-32037, ErrorKind::PluginMutationsDisabled),
281 Self::UploadNotFound => fatal(-32038, ErrorKind::UploadNotFound),
282 Self::ViewTruncated => fatal(-32040, ErrorKind::ViewTruncated),
283 Self::OutputUnavailable => fatal(-32041, ErrorKind::OutputUnavailable),
284 Self::Boundary => ErrorCodeDefinition::new(
285 -32042,
286 ErrorKind::BoundaryPruned,
287 &[ErrorKind::BoundaryUnusable, ErrorKind::NoBoundary],
288 Some(false),
289 ),
290 Self::ApprovalNotFound => fatal(-32050, ErrorKind::ApprovalNotFound),
291 Self::ApprovalAlreadyResolved => fatal(-32051, ErrorKind::ApprovalAlreadyResolved),
292 Self::ApprovalChoiceInvalid => fatal(-32052, ErrorKind::ApprovalChoiceInvalid),
293 Self::ApprovalRequirementStale => fatal(-32053, ErrorKind::ApprovalRequirementStale),
294 Self::ApprovalReviewerUnavailable => {
295 fatal(-32054, ErrorKind::ApprovalReviewerUnavailable)
296 }
297 Self::UserInputNotFound => fatal(-32055, ErrorKind::UserInputNotFound),
298 Self::UserInputAlreadySettled => fatal(-32056, ErrorKind::UserInputAlreadySettled),
299 Self::UserInputAnswerInvalid => fatal(-32057, ErrorKind::UserInputAnswerInvalid),
300 Self::MissingAnchor => {
301 ErrorCodeDefinition::experimental(-32060, ErrorKind::MissingAnchor)
302 }
303 Self::PrunedPrefix => {
304 ErrorCodeDefinition::experimental(-32061, ErrorKind::PrunedPrefix)
305 }
306 Self::WrongStream => ErrorCodeDefinition::experimental(-32062, ErrorKind::WrongStream),
307 Self::UnknownStream => {
308 ErrorCodeDefinition::experimental(-32063, ErrorKind::UnknownStream)
309 }
310 Self::UnknownProjection => {
311 ErrorCodeDefinition::experimental(-32064, ErrorKind::UnknownProjection)
312 }
313 Self::AdmissionNotFound => {
314 ErrorCodeDefinition::experimental(-32070, ErrorKind::AdmissionNotFound)
315 }
316 Self::AdmissionAlreadyResolved => {
317 ErrorCodeDefinition::experimental(-32071, ErrorKind::AdmissionAlreadyResolved)
318 }
319 Self::AdmissionChoiceInvalid => {
320 ErrorCodeDefinition::experimental(-32072, ErrorKind::AdmissionChoiceInvalid)
321 }
322 Self::UsageRefreshRateLimited => ErrorCodeDefinition::experimental_with_retry(
323 -32080,
324 ErrorKind::UsageRefreshRateLimited,
325 Some(true),
326 ),
327 Self::UsageRefreshUnavailable => {
328 ErrorCodeDefinition::experimental(-32081, ErrorKind::UsageRefreshUnavailable)
329 }
330 Self::UsageRefreshFailed => {
331 ErrorCodeDefinition::experimental(-32082, ErrorKind::UsageRefreshFailed)
332 }
333 }
334 }
335
336 #[must_use]
338 pub const fn code(self) -> i64 {
339 self.definition().code
340 }
341
342 #[must_use]
344 pub const fn kind(self) -> ErrorKind {
345 self.definition().kind
346 }
347
348 #[must_use]
353 pub const fn override_kinds(self) -> &'static [ErrorKind] {
354 self.definition().override_kinds
355 }
356
357 #[must_use]
360 pub const fn retryable(self) -> Option<bool> {
361 self.definition().retryable
362 }
363
364 #[must_use]
366 pub const fn is_experimental(self) -> bool {
367 self.definition().experimental
368 }
369}