1use std::time::Duration;
2
3#[derive(Debug, thiserror::Error)]
5pub enum WebmcpError {
6 #[error("invalid WebMCP request: {0}")]
8 InvalidRequest(String),
9 #[error("browser origin is not allowed: {0}")]
11 OriginRejected(String),
12 #[error("pairing code is expired or unknown")]
14 PairingExpired,
15 #[error("pairing code has already been used")]
17 PairingUsed,
18 #[error("WebMCP session is not authorized")]
20 Unauthorized,
21 #[error("WebMCP request exceeds the configured limit")]
23 LimitExceeded,
24 #[error("workspace path is not allowed: {0}")]
26 PathRejected(String),
27 #[error("workspace file changed since the browser read it: {path}")]
29 Conflict {
30 path: String,
32 expected: String,
34 actual: String,
36 },
37 #[error("WebMCP proposal was not found")]
39 ProposalNotFound,
40 #[error("runtime approval is required before applying a WebMCP proposal")]
42 ApprovalRequired,
43 #[error("WebMCP operation is unavailable: {0}")]
45 Unsupported(String),
46 #[error("the requested WebMCP change cannot be reverted")]
48 ChangeNotFound,
49 #[error("the WebMCP change could not be rolled back completely; operator review is required")]
51 PartialApply,
52 #[error("WebMCP event sequence gap: requested after {requested}, oldest is {oldest}")]
54 SequenceGap {
55 requested: u64,
57 oldest: u64,
59 },
60 #[error("WebMCP client is too slow to receive lifecycle events")]
62 SlowClient,
63 #[error("WebMCP operation timed out after {0:?}")]
65 Timeout(Duration),
66 #[error(transparent)]
68 Io(#[from] std::io::Error),
69 #[error(transparent)]
71 Json(#[from] serde_json::Error),
72 #[error("WebMCP runtime adapter failed: {0}")]
74 Adapter(String),
75}
76
77pub type Result<T> = std::result::Result<T, WebmcpError>;