Skip to main content

zeph_acp/
error.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4/// Errors produced by the ACP server and its subsystems.
5///
6/// Each variant corresponds to a distinct failure domain so callers can handle
7/// or propagate them appropriately.
8///
9/// # Examples
10///
11/// ```
12/// use zeph_acp::AcpError;
13///
14/// let err = AcpError::Transport("connection reset".to_owned());
15/// assert!(err.to_string().contains("transport error"));
16///
17/// let err = AcpError::TerminalTimeout { output: "partial".to_owned() };
18/// assert!(err.to_string().contains("timed out"));
19/// ```
20#[derive(Debug, thiserror::Error)]
21pub enum AcpError {
22    /// The underlying JSON-RPC transport (stdio, HTTP, WebSocket) encountered an I/O error.
23    #[error("transport error: {0}")]
24    Transport(String),
25
26    /// The connected IDE returned a protocol-level error response.
27    #[error("IDE returned error: {0}")]
28    ClientError(String),
29
30    /// The IDE did not advertise the required ACP capability.
31    #[error("capability not available: {0}")]
32    CapabilityUnavailable(String),
33
34    /// The internal async channel between the agent loop and the ACP handler was dropped.
35    ///
36    /// This typically means the session has already terminated.
37    #[error("channel closed")]
38    ChannelClosed,
39
40    /// A terminal command did not complete within the configured timeout.
41    ///
42    /// `output` contains whatever the terminal produced before the timeout.
43    #[error("terminal command timed out; partial output: {output}")]
44    TerminalTimeout { output: String },
45
46    /// The stdin data payload exceeds the 64 KiB limit.
47    #[error("stdin payload too large: {size} bytes (max 65536)")]
48    StdinTooLarge { size: usize },
49
50    /// The terminal's stdin channel was closed by the IDE before the write completed.
51    #[error("broken pipe: terminal stdin closed")]
52    BrokenPipe,
53
54    /// A `ResourceLink` URI could not be resolved (bad scheme, path traversal, SSRF, etc.).
55    #[error("resource link error: {0}")]
56    ResourceLink(String),
57}