Skip to main content

mlua_swarm/core/
errors.rs

1//! Engine error type.
2
3use crate::types::{Role, Verb};
4use thiserror::Error;
5
6/// All ways an engine operation can fail.
7#[derive(Debug, Error)]
8pub enum EngineError {
9    /// A required lock was busy and the operation gave up without retrying.
10    #[error("lock busy ({0})")]
11    LockBusy(&'static str),
12
13    /// A required lock was still busy after the configured retry budget was
14    /// exhausted.
15    #[error("lock busy after retry ({0})")]
16    LockBusyAfterRetry(&'static str),
17
18    /// The presented `CapToken`'s HMAC signature did not verify.
19    #[error("token signature invalid")]
20    BadSignature,
21
22    /// The presented `CapToken` is past its `expire_at`.
23    #[error("token expired")]
24    TokenExpired,
25
26    /// The presented `CapToken` has no uses left (`max_uses` budget spent).
27    #[error("token uses exhausted")]
28    TokenUsesExhausted,
29
30    /// No server-side record exists for the token's nonce.
31    #[error("token not found in store (nonce={0})")]
32    TokenNotFound(String),
33
34    /// The token's `Role` is not allow-listed for the requested `Verb` (see
35    /// `RoleVerbGate`).
36    #[error("role violation: role={role:?} verb={verb:?}")]
37    RoleViolation {
38        /// The role the token was minted for.
39        role: Role,
40        /// The verb that was rejected.
41        verb: Verb,
42    },
43
44    /// No task exists with the given id.
45    #[error("task not found: {0}")]
46    TaskNotFound(String),
47
48    /// No session is attached to the task.
49    #[error("session not found")]
50    SessionNotFound,
51
52    /// The resume key presented does not match any pending resume point.
53    #[error("resume key not found")]
54    ResumeKeyNotFound,
55
56    /// A generic named resource (other than task/session/token) was not
57    /// found.
58    #[error("resource not found: {0}")]
59    ResourceNotFound(String),
60
61    /// The requested state transition is not valid from the task's current
62    /// state.
63    #[error("invalid state transition: {0}")]
64    InvalidTransition(String),
65
66    /// Dispatching an attempt failed; the string carries the underlying
67    /// reason.
68    #[error("dispatch failed: {0}")]
69    DispatchFailed(String),
70
71    /// A poll operation exceeded its deadline without observing completion.
72    #[error("poll timeout")]
73    PollTimeout,
74
75    /// The task was cancelled.
76    #[error("cancelled")]
77    Cancelled,
78
79    /// A sub-task spawn would exceed the configured `max_spawn_depth`.
80    #[error("spawn depth exceeded: {current} >= max {max}")]
81    SpawnDepthExceeded {
82        /// The depth that would result from this spawn.
83        current: u32,
84        /// The configured maximum allowed depth.
85        max: u32,
86    },
87
88    /// The presented token is bound to a different task than the one
89    /// referenced by the call.
90    #[error("token task mismatch: token bound to {bound}, arg was {arg}")]
91    TokenTaskMismatch {
92        /// The task id the token is actually bound to.
93        bound: String,
94        /// The task id that was passed in the call.
95        arg: String,
96    },
97
98    /// Catch-all for invariant violations that don't have a dedicated
99    /// variant yet.
100    #[error("internal: {0}")]
101    Internal(String),
102}