Skip to main content

muse_code_sdk/msp/error/
registry.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use super::ErrorKind;
4
5/// The session-lifecycle wire code for [`ErrorKind::SessionNotLoaded`]: one
6/// shared symbol so producers and test assertions cannot drift on the literal.
7pub const SESSION_NOT_LOADED_CODE: i64 = -32024;
8
9/// The session-lifecycle wire code for [`ErrorKind::SessionStreamMismatch`]:
10/// the resolved store's own stream id is not the requested session, so every
11/// write lane refuses before it can append a fabricated history.
12pub const SESSION_STREAM_MISMATCH_CODE: i64 = -32025;
13
14/// The session-lifecycle wire code for [`ErrorKind::LimitsAboveMax`]: one
15/// shared symbol so the `session/start` producer and test assertions cannot
16/// drift on the literal.
17pub const LIMITS_ABOVE_MAX_CODE: i64 = -32028;
18
19/// The v1 error codes enrolled in the public bundle.
20///
21/// Enrolment tracks what the BINARY can emit, not what the bundle's method
22/// index has reached: the export is exact for the binary that produced it, so a
23/// code a v1 host puts on the wire is enrolled here even while its method's
24/// params/result types are still pending. Of the `-32060…-32069` raw-log block,
25/// only the five experimental rows are enrolled; the rest stays out because a
26/// v1 host never emits it.
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28#[non_exhaustive]
29pub enum ErrorCode {
30    /// `-32700` — unparseable line.
31    ParseError,
32    /// `-32600` — invalid frame or handshake ordering.
33    InvalidRequest,
34    /// `-32601` — unknown or ungated-experimental method.
35    MethodNotFound,
36    /// `-32602` — malformed params or ungated-experimental field/variant.
37    InvalidParams,
38    /// `-32603` — unexpected server failure.
39    Internal,
40    /// `-32001` — ingress saturated.
41    Overloaded,
42    /// `-32002` — frame or params over the limit.
43    InputTooLarge,
44    /// `-32010` — missing capability grant.
45    CapabilityRequired,
46    /// `-32011` — run/item/subscription/cursor anchor missing.
47    NotFound,
48    /// `-32013` — user interrupt pre-empted the request.
49    Interrupted,
50    /// `-32014` — cancellation pre-empted the request.
51    Cancelled,
52    /// `-32020` — no log resolves for `sessionId`.
53    SessionNotFound,
54    /// `-32021` — writer lease held by another process.
55    SessionInUse,
56    /// `-32022` — multiple canonical logs for the id.
57    SessionAmbiguous,
58    /// `-32023` — `cutPoint.lastTurnId` unknown or in-progress.
59    ForkBoundaryInvalid,
60    /// `-32024` — log exists but the session is not loaded on this host.
61    SessionNotLoaded,
62    /// `-32025` — the store's own stream id is not the requested session
63    /// (a moved or renamed session directory).
64    SessionStreamMismatch,
65    /// `-32028` — a `session/start` choice is wider than the host ceiling on at
66    /// least one axis.
67    LimitsAboveMax,
68    /// `-32029` — a worktree action names an untrusted repository.
69    WorkspaceNotTrusted,
70    /// `-32030` — durable runtime rejection; `data.reason` is snake_case.
71    CommandRejected,
72    /// `-32031` — command-admission queue full; `data.capacity` present.
73    Backpressured,
74    /// `-32032` — the skill selector names no user-invocable skill in this
75    /// session's catalog.
76    SkillNotFound,
77    /// `-32033` — computer use is unavailable on this host.
78    ComputerUseUnavailable,
79    /// `-32034` — the plugin verb names no configured marketplace.
80    MarketplaceNotFound,
81    /// `-32035` — the install arm names no plugin in the named store.
82    PluginNotFound,
83    /// `-32036` — marketplace add over an already-configured name.
84    MarketplaceAlreadyExists,
85    /// `-32037` — the managed policy disables plugin mutation.
86    PluginMutationsDisabled,
87    /// `-32038` — a `video` input part names an upload id with no completed
88    /// upload.
89    UploadNotFound,
90    /// `-32040` — requested range predates the retained view.
91    ViewTruncated,
92    /// `-32041` — an `item/readOutput` ref exists but its bytes are not
93    /// servable; `data.availability` carries the durable
94    /// `ToolOutputAvailability`.
95    OutputUnavailable,
96    /// `-32042` — installed boundary pruned, unusable, or absent.
97    Boundary,
98    /// `-32050` — `approvalId` names no approval record in this session.
99    ApprovalNotFound,
100    /// `-32051` — decide after the durable terminal.
101    ApprovalAlreadyResolved,
102    /// `-32052` — `choiceId` is not among the current `availableChoices`.
103    ApprovalChoiceInvalid,
104    /// `-32053` — `requirementId` is not the current requirement.
105    ApprovalRequirementStale,
106    /// `-32054` — protected-write decision with no live reviewer.
107    ApprovalReviewerUnavailable,
108    /// `-32055` — `userInputId` names no prompt in this session.
109    UserInputNotFound,
110    /// `-32056` — answer/cancel/clarify after settlement.
111    UserInputAlreadySettled,
112    /// `-32057` — answers do not match the prompt's questions or bounds.
113    UserInputAnswerInvalid,
114    /// `-32060` — cursor anchor names no position of the requested stream.
115    MissingAnchor,
116    /// `-32061` — anchor (or origin) falls in a retention-pruned prefix.
117    PrunedPrefix,
118    /// `-32062` — anchor id belongs to a different stream of the session.
119    WrongStream,
120    /// `-32063` — stream not present in the session.
121    UnknownStream,
122    /// `-32064` — projection name not registered.
123    UnknownProjection,
124    /// `-32070` — `admissionId` names no admission record in this session.
125    AdmissionNotFound,
126    /// `-32071` — decide after the durable terminal.
127    AdmissionAlreadyResolved,
128    /// `-32072` — `choiceId` is not among the current `availableChoices`.
129    AdmissionChoiceInvalid,
130}
131
132#[derive(Clone, Copy)]
133struct ErrorCodeDefinition {
134    code: i64,
135    kind: ErrorKind,
136    override_kinds: &'static [ErrorKind],
137    retryable: Option<bool>,
138    experimental: bool,
139}
140
141impl ErrorCodeDefinition {
142    const fn new(
143        code: i64,
144        kind: ErrorKind,
145        override_kinds: &'static [ErrorKind],
146        retryable: Option<bool>,
147    ) -> Self {
148        Self {
149            code,
150            kind,
151            override_kinds,
152            retryable,
153            experimental: false,
154        }
155    }
156
157    /// An experimental-tier row: exported only in the experimental bundle
158    /// render, like the experimental method rows.
159    const fn experimental(code: i64, kind: ErrorKind) -> Self {
160        Self {
161            code,
162            kind,
163            override_kinds: &[],
164            retryable: Some(false),
165            experimental: true,
166        }
167    }
168}
169
170/// A single-kind row a retry cannot fix (`retryable: false`). The column is the
171/// CODE's default; a payload that knows better sets `data.retryable`.
172const fn fatal(code: i64, kind: ErrorKind) -> ErrorCodeDefinition {
173    ErrorCodeDefinition::new(code, kind, &[], Some(false))
174}
175
176/// A single-kind saturation row (`retryable: true`): the queue drains, so the
177/// same request can succeed later.
178const fn drains(code: i64, kind: ErrorKind) -> ErrorCodeDefinition {
179    ErrorCodeDefinition::new(code, kind, &[], Some(true))
180}
181
182/// A single-kind pre-emption row (`retryable` absent): retry is not the
183/// question — the outcome arrives on the view stream.
184const fn preempted(code: i64, kind: ErrorKind) -> ErrorCodeDefinition {
185    ErrorCodeDefinition::new(code, kind, &[], None)
186}
187
188impl ErrorCode {
189    /// Every code enrolled in the public bundle, in registry order: the 37
190    /// stable rows plus 10 experimental rows (5 raw-log, 1 workspace-trust, 1
191    /// limits, 3 admission), which render only in the experimental bundle.
192    pub const ALL: [Self; 47] = [
193        Self::ParseError,
194        Self::InvalidRequest,
195        Self::MethodNotFound,
196        Self::InvalidParams,
197        Self::Internal,
198        Self::Overloaded,
199        Self::InputTooLarge,
200        Self::CapabilityRequired,
201        Self::NotFound,
202        Self::Interrupted,
203        Self::Cancelled,
204        Self::SessionNotFound,
205        Self::SessionInUse,
206        Self::SessionAmbiguous,
207        Self::ForkBoundaryInvalid,
208        Self::SessionNotLoaded,
209        Self::SessionStreamMismatch,
210        Self::LimitsAboveMax,
211        Self::WorkspaceNotTrusted,
212        Self::CommandRejected,
213        Self::Backpressured,
214        Self::SkillNotFound,
215        Self::ComputerUseUnavailable,
216        Self::MarketplaceNotFound,
217        Self::PluginNotFound,
218        Self::MarketplaceAlreadyExists,
219        Self::PluginMutationsDisabled,
220        Self::UploadNotFound,
221        Self::ViewTruncated,
222        Self::OutputUnavailable,
223        Self::Boundary,
224        Self::ApprovalNotFound,
225        Self::ApprovalAlreadyResolved,
226        Self::ApprovalChoiceInvalid,
227        Self::ApprovalRequirementStale,
228        Self::ApprovalReviewerUnavailable,
229        Self::UserInputNotFound,
230        Self::UserInputAlreadySettled,
231        Self::UserInputAnswerInvalid,
232        Self::MissingAnchor,
233        Self::PrunedPrefix,
234        Self::WrongStream,
235        Self::UnknownStream,
236        Self::UnknownProjection,
237        Self::AdmissionNotFound,
238        Self::AdmissionAlreadyResolved,
239        Self::AdmissionChoiceInvalid,
240    ];
241
242    /// This code's complete registry row. Keeping the row together prevents
243    /// the generated bundle columns from drifting across separate matches, so
244    /// this stays ONE wildcard-free match over every variant: a new code fails
245    /// to compile until its row exists. The three shape helpers below carry the
246    /// `retryable` column's vocabulary — a shared name per column value, not a
247    /// default anyone can inherit by omission.
248    const fn definition(self) -> ErrorCodeDefinition {
249        match self {
250            Self::ParseError => fatal(-32700, ErrorKind::ParseError),
251            Self::InvalidRequest => ErrorCodeDefinition::new(
252                -32600,
253                ErrorKind::InvalidRequest,
254                &[ErrorKind::NotInitialized, ErrorKind::AlreadyInitialized],
255                Some(false),
256            ),
257            Self::MethodNotFound => ErrorCodeDefinition::new(
258                -32601,
259                ErrorKind::MethodNotFound,
260                &[ErrorKind::ExperimentalRequired],
261                Some(false),
262            ),
263            Self::InvalidParams => ErrorCodeDefinition::new(
264                -32602,
265                ErrorKind::InvalidParams,
266                &[ErrorKind::ExperimentalRequired],
267                Some(false),
268            ),
269            Self::Internal => ErrorCodeDefinition::new(
270                -32603,
271                ErrorKind::Internal,
272                &[
273                    ErrorKind::PageEventTooLarge,
274                    ErrorKind::OutputResultTooLarge,
275                ],
276                Some(false),
277            ),
278            Self::Overloaded => drains(-32001, ErrorKind::Overloaded),
279            Self::InputTooLarge => fatal(-32002, ErrorKind::InputTooLarge),
280            Self::CapabilityRequired => fatal(-32010, ErrorKind::CapabilityRequired),
281            Self::NotFound => fatal(-32011, ErrorKind::NotFound),
282            Self::Interrupted => preempted(-32013, ErrorKind::Interrupted),
283            Self::Cancelled => preempted(-32014, ErrorKind::Cancelled),
284            Self::SessionNotFound => fatal(-32020, ErrorKind::SessionNotFound),
285            Self::SessionInUse => fatal(-32021, ErrorKind::SessionInUse),
286            Self::SessionAmbiguous => fatal(-32022, ErrorKind::SessionAmbiguous),
287            Self::ForkBoundaryInvalid => fatal(-32023, ErrorKind::ForkBoundaryInvalid),
288            Self::SessionNotLoaded => fatal(SESSION_NOT_LOADED_CODE, ErrorKind::SessionNotLoaded),
289            Self::SessionStreamMismatch => fatal(
290                SESSION_STREAM_MISMATCH_CODE,
291                ErrorKind::SessionStreamMismatch,
292            ),
293            Self::LimitsAboveMax => {
294                ErrorCodeDefinition::experimental(LIMITS_ABOVE_MAX_CODE, ErrorKind::LimitsAboveMax)
295            }
296            Self::WorkspaceNotTrusted => {
297                ErrorCodeDefinition::experimental(-32029, ErrorKind::WorkspaceNotTrusted)
298            }
299            Self::CommandRejected => fatal(-32030, ErrorKind::CommandRejected),
300            Self::Backpressured => drains(-32031, ErrorKind::Backpressured),
301            Self::SkillNotFound => fatal(-32032, ErrorKind::SkillNotFound),
302            Self::ComputerUseUnavailable => fatal(-32033, ErrorKind::ComputerUseUnavailable),
303            Self::MarketplaceNotFound => fatal(-32034, ErrorKind::MarketplaceNotFound),
304            Self::PluginNotFound => fatal(-32035, ErrorKind::PluginNotFound),
305            Self::MarketplaceAlreadyExists => fatal(-32036, ErrorKind::MarketplaceAlreadyExists),
306            Self::PluginMutationsDisabled => fatal(-32037, ErrorKind::PluginMutationsDisabled),
307            Self::UploadNotFound => fatal(-32038, ErrorKind::UploadNotFound),
308            Self::ViewTruncated => fatal(-32040, ErrorKind::ViewTruncated),
309            Self::OutputUnavailable => fatal(-32041, ErrorKind::OutputUnavailable),
310            Self::Boundary => ErrorCodeDefinition::new(
311                -32042,
312                ErrorKind::BoundaryPruned,
313                &[ErrorKind::BoundaryUnusable, ErrorKind::NoBoundary],
314                Some(false),
315            ),
316            Self::ApprovalNotFound => fatal(-32050, ErrorKind::ApprovalNotFound),
317            Self::ApprovalAlreadyResolved => fatal(-32051, ErrorKind::ApprovalAlreadyResolved),
318            Self::ApprovalChoiceInvalid => fatal(-32052, ErrorKind::ApprovalChoiceInvalid),
319            Self::ApprovalRequirementStale => fatal(-32053, ErrorKind::ApprovalRequirementStale),
320            Self::ApprovalReviewerUnavailable => {
321                fatal(-32054, ErrorKind::ApprovalReviewerUnavailable)
322            }
323            Self::UserInputNotFound => fatal(-32055, ErrorKind::UserInputNotFound),
324            Self::UserInputAlreadySettled => fatal(-32056, ErrorKind::UserInputAlreadySettled),
325            Self::UserInputAnswerInvalid => fatal(-32057, ErrorKind::UserInputAnswerInvalid),
326            Self::MissingAnchor => {
327                ErrorCodeDefinition::experimental(-32060, ErrorKind::MissingAnchor)
328            }
329            Self::PrunedPrefix => {
330                ErrorCodeDefinition::experimental(-32061, ErrorKind::PrunedPrefix)
331            }
332            Self::WrongStream => ErrorCodeDefinition::experimental(-32062, ErrorKind::WrongStream),
333            Self::UnknownStream => {
334                ErrorCodeDefinition::experimental(-32063, ErrorKind::UnknownStream)
335            }
336            Self::UnknownProjection => {
337                ErrorCodeDefinition::experimental(-32064, ErrorKind::UnknownProjection)
338            }
339            Self::AdmissionNotFound => {
340                ErrorCodeDefinition::experimental(-32070, ErrorKind::AdmissionNotFound)
341            }
342            Self::AdmissionAlreadyResolved => {
343                ErrorCodeDefinition::experimental(-32071, ErrorKind::AdmissionAlreadyResolved)
344            }
345            Self::AdmissionChoiceInvalid => {
346                ErrorCodeDefinition::experimental(-32072, ErrorKind::AdmissionChoiceInvalid)
347            }
348        }
349    }
350
351    /// The wire integer.
352    #[must_use]
353    pub const fn code(self) -> i64 {
354        self.definition().code
355    }
356
357    /// The primary `data.kind` for this code.
358    #[must_use]
359    pub const fn kind(self) -> ErrorKind {
360        self.definition().kind
361    }
362
363    /// Kinds that override the primary on this code: handshake-ordering
364    /// overrides on `-32600`, the experimental gate on `-32601`/`-32602`, the
365    /// permanent page/output budget residuals on `-32603`, and the
366    /// unusable/absent boundary arms on `-32042`.
367    #[must_use]
368    pub const fn override_kinds(self) -> &'static [ErrorKind] {
369        self.definition().override_kinds
370    }
371
372    /// Whether a retry can succeed. `None` for the pre-emption codes, where
373    /// retry is not applicable — the outcome arrives on the view stream.
374    #[must_use]
375    pub const fn retryable(self) -> Option<bool> {
376        self.definition().retryable
377    }
378
379    /// Whether this row renders only in the experimental bundle.
380    #[must_use]
381    pub const fn is_experimental(self) -> bool {
382        self.definition().experimental
383    }
384}