Skip to main content

vtcode_webmcp/
error.rs

1use std::time::Duration;
2
3/// Errors returned by the WebMCP bridge and its runtime adapters.
4#[derive(Debug, thiserror::Error)]
5pub enum WebmcpError {
6    /// The request or configuration is malformed.
7    #[error("invalid WebMCP request: {0}")]
8    InvalidRequest(String),
9    /// The browser origin is not explicitly allowed.
10    #[error("browser origin is not allowed: {0}")]
11    OriginRejected(String),
12    /// The pairing code is unknown or has expired.
13    #[error("pairing code is expired or unknown")]
14    PairingExpired,
15    /// A one-time pairing code was already consumed.
16    #[error("pairing code has already been used")]
17    PairingUsed,
18    /// The session token has been revoked or is not recognized.
19    #[error("WebMCP session is not authorized")]
20    Unauthorized,
21    /// A request exceeded a configured transport limit.
22    #[error("WebMCP request exceeds the configured limit")]
23    LimitExceeded,
24    /// The requested path is outside the workspace boundary.
25    #[error("workspace path is not allowed: {0}")]
26    PathRejected(String),
27    /// The browser based its edit on a stale file.
28    #[error("workspace file changed since the browser read it: {path}")]
29    Conflict {
30        /// Relative path of the conflicting file.
31        path: String,
32        /// Digest supplied by the browser.
33        expected: String,
34        /// Digest observed by the adapter.
35        actual: String,
36    },
37    /// A proposal identifier was not found.
38    #[error("WebMCP proposal was not found")]
39    ProposalNotFound,
40    /// A mutation was requested without terminal authorization.
41    #[error("runtime approval is required before applying a WebMCP proposal")]
42    ApprovalRequired,
43    /// The selected adapter does not implement the requested operation.
44    #[error("WebMCP operation is unavailable: {0}")]
45    Unsupported(String),
46    /// A revert identifier was not found or is no longer current.
47    #[error("the requested WebMCP change cannot be reverted")]
48    ChangeNotFound,
49    /// A multi-file mutation could not be fully rolled back.
50    #[error("the WebMCP change could not be rolled back completely; operator review is required")]
51    PartialApply,
52    /// The event hub cannot replay the requested range.
53    #[error("WebMCP event sequence gap: requested after {requested}, oldest is {oldest}")]
54    SequenceGap {
55        /// Last sequence known by the reconnecting client.
56        requested: u64,
57        /// Oldest sequence retained by the hub.
58        oldest: u64,
59    },
60    /// A subscriber could not keep up with lifecycle events.
61    #[error("WebMCP client is too slow to receive lifecycle events")]
62    SlowClient,
63    /// An adapter operation exceeded its deadline.
64    #[error("WebMCP operation timed out after {0:?}")]
65    Timeout(Duration),
66    /// An underlying filesystem or process operation failed.
67    #[error(transparent)]
68    Io(#[from] std::io::Error),
69    /// A JSON protocol payload failed to decode.
70    #[error(transparent)]
71    Json(#[from] serde_json::Error),
72    /// An adapter returned a contextual failure.
73    #[error("WebMCP runtime adapter failed: {0}")]
74    Adapter(String),
75}
76
77/// Result alias used throughout the bridge.
78pub type Result<T> = std::result::Result<T, WebmcpError>;