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