Skip to main content

wasm_capability_contract/component/error/
capability_error.rs

1//! [`CapabilityError`] — every actionable failure mode for
2//! `ComponentValidator::validate` and `CapabilityEngine::load`/`invoke`.
3
4/// Everything `ComponentValidator::validate` or a real `CapabilityEngine`
5/// can fail with, named so the message alone tells the caller what to fix.
6///
7/// Split into two phases, matching the port's own split: validation/load-time
8/// (`UnsupportedContractVersion`, `InvalidManifest`, `CapabilityUnavailable`
9/// — rejected before a route is ever registered) and invocation-time
10/// (`Trap`, `InvalidOutput`, `ResourceExhausted`, `Cancelled`, `Timeout` —
11/// surfaced from a live `CapabilityEngine::invoke` call). `#1` scoped this
12/// enum down to only the first phase since no `CapabilityEngine` existed yet;
13/// `#3` (ADR-001's component engine wiring) adds the second phase back.
14#[derive(Debug, thiserror::Error, PartialEq, Eq)]
15pub enum CapabilityError {
16    /// The manifest's `contract_version` is not one this host understands.
17    #[error("unsupported contract version: {0}")]
18    UnsupportedContractVersion(String),
19    /// The manifest or component bytes are structurally invalid.
20    #[error("invalid manifest: {0}")]
21    InvalidManifest(String),
22    /// A declared capability has no matching grant, or its scope is
23    /// empty/wildcarded in a way its kind never permits, or (at engine
24    /// time) a granted capability has no matching real dispatcher wired.
25    #[error("capability unavailable: {0}")]
26    CapabilityUnavailable(String),
27    /// The component trapped (panicked/aborted) during execution.
28    #[error("component trap: {0}")]
29    Trap(String),
30    /// The component produced output that does not match its declared
31    /// export shape.
32    #[error("invalid output: {0}")]
33    InvalidOutput(String),
34    /// A configured memory, CPU, concurrency, or queue limit was exceeded.
35    #[error("resource exhausted: {0}")]
36    ResourceExhausted(String),
37    /// The invocation was cancelled before it completed.
38    #[error("invocation cancelled")]
39    Cancelled,
40    /// The invocation exceeded its configured deadline.
41    #[error("invocation timed out")]
42    Timeout,
43}