claude_codes/
error.rs

1//! Error types for the Claude Code protocol
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum Error {
7    #[error("JSON serialization error: {0}")]
8    Json(#[from] serde_json::Error),
9
10    #[error("IO error: {0}")]
11    Io(#[from] std::io::Error),
12
13    #[error("Protocol error: {0}")]
14    Protocol(String),
15
16    #[error("Invalid message type: {0}")]
17    InvalidMessageType(String),
18
19    #[error("Missing required field: {0}")]
20    MissingField(String),
21
22    #[error("Invalid state transition: {0}")]
23    InvalidState(String),
24
25    #[error("Timeout occurred")]
26    Timeout,
27
28    #[error("Connection closed")]
29    ConnectionClosed,
30
31    #[error("Deserialization error: {0}")]
32    Deserialization(String),
33
34    #[error("Session UUID not yet available - no response received")]
35    SessionNotInitialized,
36
37    #[error("Unknown error: {0}")]
38    Unknown(String),
39}
40
41pub type Result<T> = std::result::Result<T, Error>;