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 STARTUP_PENDING_CODE: i64 = -32015;
20
21pub const LIMITS_ABOVE_MAX_CODE: i64 = -32028;
25
26pub const DAEMON_DRAINING_CODE: i64 = -32039;
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41#[non_exhaustive]
42pub enum ErrorCode {
43 ParseError,
45 InvalidRequest,
47 MethodNotFound,
49 InvalidParams,
51 Internal,
53 Overloaded,
55 InputTooLarge,
57 CapabilityRequired,
59 NotFound,
61 Interrupted,
63 Cancelled,
65 SessionNotFound,
67 SessionInUse,
69 SessionAmbiguous,
71 ForkBoundaryInvalid,
73 SessionNotLoaded,
75 SessionStreamMismatch,
78 DaemonDraining,
82 StartupPending,
85 LimitsAboveMax,
88 WorkspaceNotTrusted,
90 CommandRejected,
92 Backpressured,
94 SkillNotFound,
97 ComputerUseUnavailable,
99 MarketplaceNotFound,
101 PluginNotFound,
103 MarketplaceAlreadyExists,
105 PluginMutationsDisabled,
107 UploadNotFound,
110 ViewTruncated,
112 OutputUnavailable,
116 Boundary,
118 ApprovalNotFound,
120 ApprovalAlreadyResolved,
122 ApprovalChoiceInvalid,
124 ApprovalRequirementStale,
126 ApprovalReviewerUnavailable,
128 UserInputNotFound,
130 UserInputAlreadySettled,
132 UserInputAnswerInvalid,
134 ApprovalBrokerUnavailable,
136 ApprovalResolving,
138 MissingAnchor,
140 PrunedPrefix,
142 WrongStream,
144 UnknownStream,
146 UnknownProjection,
148 AdmissionNotFound,
150 AdmissionAlreadyResolved,
152 AdmissionChoiceInvalid,
154 UsageRefreshRateLimited,
156 UsageRefreshUnavailable,
158 UsageRefreshFailed,
160}
161
162impl ErrorCode {
163 pub const ALL: [Self; 54] = [
168 Self::ParseError,
169 Self::InvalidRequest,
170 Self::MethodNotFound,
171 Self::InvalidParams,
172 Self::Internal,
173 Self::Overloaded,
174 Self::InputTooLarge,
175 Self::CapabilityRequired,
176 Self::NotFound,
177 Self::Interrupted,
178 Self::Cancelled,
179 Self::StartupPending,
180 Self::SessionNotFound,
181 Self::SessionInUse,
182 Self::SessionAmbiguous,
183 Self::ForkBoundaryInvalid,
184 Self::SessionNotLoaded,
185 Self::SessionStreamMismatch,
186 Self::DaemonDraining,
187 Self::LimitsAboveMax,
188 Self::WorkspaceNotTrusted,
189 Self::CommandRejected,
190 Self::Backpressured,
191 Self::SkillNotFound,
192 Self::ComputerUseUnavailable,
193 Self::MarketplaceNotFound,
194 Self::PluginNotFound,
195 Self::MarketplaceAlreadyExists,
196 Self::PluginMutationsDisabled,
197 Self::UploadNotFound,
198 Self::ViewTruncated,
199 Self::OutputUnavailable,
200 Self::Boundary,
201 Self::ApprovalNotFound,
202 Self::ApprovalAlreadyResolved,
203 Self::ApprovalChoiceInvalid,
204 Self::ApprovalRequirementStale,
205 Self::ApprovalReviewerUnavailable,
206 Self::UserInputNotFound,
207 Self::UserInputAlreadySettled,
208 Self::UserInputAnswerInvalid,
209 Self::ApprovalBrokerUnavailable,
210 Self::ApprovalResolving,
211 Self::MissingAnchor,
212 Self::PrunedPrefix,
213 Self::WrongStream,
214 Self::UnknownStream,
215 Self::UnknownProjection,
216 Self::AdmissionNotFound,
217 Self::AdmissionAlreadyResolved,
218 Self::AdmissionChoiceInvalid,
219 Self::UsageRefreshRateLimited,
220 Self::UsageRefreshUnavailable,
221 Self::UsageRefreshFailed,
222 ];
223
224 const fn definition(self) -> ErrorCodeDefinition {
231 match self {
232 Self::ParseError => fatal(-32700, ErrorKind::ParseError),
233 Self::InvalidRequest => ErrorCodeDefinition::new(
234 -32600,
235 ErrorKind::InvalidRequest,
236 &[ErrorKind::NotInitialized, ErrorKind::AlreadyInitialized],
237 Some(false),
238 ),
239 Self::MethodNotFound => ErrorCodeDefinition::new(
240 -32601,
241 ErrorKind::MethodNotFound,
242 &[ErrorKind::ExperimentalRequired],
243 Some(false),
244 ),
245 Self::InvalidParams => ErrorCodeDefinition::new(
246 -32602,
247 ErrorKind::InvalidParams,
248 &[ErrorKind::ExperimentalRequired],
249 Some(false),
250 ),
251 Self::Internal => ErrorCodeDefinition::new(
252 -32603,
253 ErrorKind::Internal,
254 &[
255 ErrorKind::PageEventTooLarge,
256 ErrorKind::OutputResultTooLarge,
257 ],
258 Some(false),
259 ),
260 Self::Overloaded => drains(-32001, ErrorKind::Overloaded),
261 Self::InputTooLarge => fatal(-32002, ErrorKind::InputTooLarge),
262 Self::CapabilityRequired => fatal(-32010, ErrorKind::CapabilityRequired),
263 Self::NotFound => fatal(-32011, ErrorKind::NotFound),
264 Self::Interrupted => preempted(-32013, ErrorKind::Interrupted),
265 Self::Cancelled => preempted(-32014, ErrorKind::Cancelled),
266 Self::StartupPending => ErrorCodeDefinition::experimental_with_retry(
267 STARTUP_PENDING_CODE,
268 ErrorKind::StartupPending,
269 Some(true),
270 ),
271 Self::SessionNotFound => fatal(-32020, ErrorKind::SessionNotFound),
272 Self::SessionInUse => fatal(-32021, ErrorKind::SessionInUse),
273 Self::SessionAmbiguous => fatal(-32022, ErrorKind::SessionAmbiguous),
274 Self::ForkBoundaryInvalid => fatal(-32023, ErrorKind::ForkBoundaryInvalid),
275 Self::SessionNotLoaded => fatal(SESSION_NOT_LOADED_CODE, ErrorKind::SessionNotLoaded),
276 Self::SessionStreamMismatch => fatal(
277 SESSION_STREAM_MISMATCH_CODE,
278 ErrorKind::SessionStreamMismatch,
279 ),
280 Self::DaemonDraining => ErrorCodeDefinition::experimental_with_retry(
281 DAEMON_DRAINING_CODE,
282 ErrorKind::DaemonDraining,
283 Some(true),
284 ),
285 Self::LimitsAboveMax => {
286 ErrorCodeDefinition::experimental(LIMITS_ABOVE_MAX_CODE, ErrorKind::LimitsAboveMax)
287 }
288 Self::WorkspaceNotTrusted => {
289 ErrorCodeDefinition::experimental(-32029, ErrorKind::WorkspaceNotTrusted)
290 }
291 Self::CommandRejected => fatal(-32030, ErrorKind::CommandRejected),
292 Self::Backpressured => drains(-32031, ErrorKind::Backpressured),
293 Self::SkillNotFound => fatal(-32032, ErrorKind::SkillNotFound),
294 Self::ComputerUseUnavailable => fatal(-32033, ErrorKind::ComputerUseUnavailable),
295 Self::MarketplaceNotFound => fatal(-32034, ErrorKind::MarketplaceNotFound),
296 Self::PluginNotFound => fatal(-32035, ErrorKind::PluginNotFound),
297 Self::MarketplaceAlreadyExists => fatal(-32036, ErrorKind::MarketplaceAlreadyExists),
298 Self::PluginMutationsDisabled => fatal(-32037, ErrorKind::PluginMutationsDisabled),
299 Self::UploadNotFound => fatal(-32038, ErrorKind::UploadNotFound),
300 Self::ViewTruncated => fatal(-32040, ErrorKind::ViewTruncated),
301 Self::OutputUnavailable => fatal(-32041, ErrorKind::OutputUnavailable),
302 Self::Boundary => ErrorCodeDefinition::new(
303 -32042,
304 ErrorKind::BoundaryPruned,
305 &[ErrorKind::BoundaryUnusable, ErrorKind::NoBoundary],
306 Some(false),
307 ),
308 Self::ApprovalNotFound => fatal(-32050, ErrorKind::ApprovalNotFound),
309 Self::ApprovalAlreadyResolved => fatal(-32051, ErrorKind::ApprovalAlreadyResolved),
310 Self::ApprovalChoiceInvalid => fatal(-32052, ErrorKind::ApprovalChoiceInvalid),
311 Self::ApprovalRequirementStale => fatal(-32053, ErrorKind::ApprovalRequirementStale),
312 Self::ApprovalReviewerUnavailable => {
313 fatal(-32054, ErrorKind::ApprovalReviewerUnavailable)
314 }
315 Self::UserInputNotFound => fatal(-32055, ErrorKind::UserInputNotFound),
316 Self::UserInputAlreadySettled => fatal(-32056, ErrorKind::UserInputAlreadySettled),
317 Self::UserInputAnswerInvalid => fatal(-32057, ErrorKind::UserInputAnswerInvalid),
318 Self::ApprovalBrokerUnavailable => drains(-32058, ErrorKind::ApprovalBrokerUnavailable),
319 Self::ApprovalResolving => fatal(-32059, ErrorKind::ApprovalResolving),
320 Self::MissingAnchor => {
321 ErrorCodeDefinition::experimental(-32060, ErrorKind::MissingAnchor)
322 }
323 Self::PrunedPrefix => {
324 ErrorCodeDefinition::experimental(-32061, ErrorKind::PrunedPrefix)
325 }
326 Self::WrongStream => ErrorCodeDefinition::experimental(-32062, ErrorKind::WrongStream),
327 Self::UnknownStream => {
328 ErrorCodeDefinition::experimental(-32063, ErrorKind::UnknownStream)
329 }
330 Self::UnknownProjection => {
331 ErrorCodeDefinition::experimental(-32064, ErrorKind::UnknownProjection)
332 }
333 Self::AdmissionNotFound => {
334 ErrorCodeDefinition::experimental(-32070, ErrorKind::AdmissionNotFound)
335 }
336 Self::AdmissionAlreadyResolved => {
337 ErrorCodeDefinition::experimental(-32071, ErrorKind::AdmissionAlreadyResolved)
338 }
339 Self::AdmissionChoiceInvalid => {
340 ErrorCodeDefinition::experimental(-32072, ErrorKind::AdmissionChoiceInvalid)
341 }
342 Self::UsageRefreshRateLimited => ErrorCodeDefinition::experimental_with_retry(
343 -32080,
344 ErrorKind::UsageRefreshRateLimited,
345 Some(true),
346 ),
347 Self::UsageRefreshUnavailable => {
348 ErrorCodeDefinition::experimental(-32081, ErrorKind::UsageRefreshUnavailable)
349 }
350 Self::UsageRefreshFailed => {
351 ErrorCodeDefinition::experimental(-32082, ErrorKind::UsageRefreshFailed)
352 }
353 }
354 }
355
356 #[must_use]
358 pub const fn code(self) -> i64 {
359 self.definition().code
360 }
361
362 #[must_use]
364 pub const fn kind(self) -> ErrorKind {
365 self.definition().kind
366 }
367
368 #[must_use]
373 pub const fn override_kinds(self) -> &'static [ErrorKind] {
374 self.definition().override_kinds
375 }
376
377 #[must_use]
380 pub const fn retryable(self) -> Option<bool> {
381 self.definition().retryable
382 }
383
384 #[must_use]
386 pub const fn is_experimental(self) -> bool {
387 self.definition().experimental
388 }
389}