Skip to main content

lattice_agent/
error.rs

1//! Error surface for the agent capability port.
2
3/// Failures raised by [`crate`]'s port operations. Distinct from an adapter's
4/// protocol error: this describes the *editor* refusing or failing, never a
5/// wire fault.
6#[derive(Debug, thiserror::Error)]
7pub enum AgentError {
8    /// Nothing is draining the bus on the host side — a boot misconfiguration,
9    /// or the editor is shutting down.
10    #[error("editor not reachable: {0}")]
11    Bus(String),
12    /// A review's reply channel dropped before the user decided (the diff was
13    /// closed, the session died, the editor went away).
14    #[error("cancelled: {0}")]
15    Cancelled(String),
16    /// A read or write against the editor failed.
17    #[error("editor io error: {0}")]
18    Io(String),
19}
20
21/// Convenience alias.
22pub type Result<T> = std::result::Result<T, AgentError>;
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn error_display_is_prefixed() {
30        assert_eq!(
31            AgentError::Bus("no receiver".into()).to_string(),
32            "editor not reachable: no receiver"
33        );
34        assert_eq!(
35            AgentError::Cancelled("diff closed".into()).to_string(),
36            "cancelled: diff closed"
37        );
38        assert_eq!(
39            AgentError::Io("read failed".into()).to_string(),
40            "editor io error: read failed"
41        );
42    }
43}