Skip to main content

jsonrpc_fdpass/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during JSON-RPC operations.
4#[derive(Error, Debug)]
5pub enum Error {
6    /// JSON serialization or deserialization failed.
7    #[error("JSON parsing error: {0}")]
8    Json(#[from] serde_json::Error),
9
10    /// An I/O error occurred.
11    #[error("IO error: {0}")]
12    Io(#[from] std::io::Error),
13
14    /// The message contained invalid JSON.
15    #[error("Protocol framing error: invalid JSON in message")]
16    FramingError,
17
18    /// The `fds` field in the message doesn't match the number of received file descriptors.
19    #[error(
20        "File descriptor count mismatch: fds field specifies {expected}, but {found} FDs available"
21    )]
22    MismatchedCount {
23        /// Number of file descriptors specified in the `fds` field.
24        expected: usize,
25        /// Number of file descriptors actually available.
26        found: usize,
27    },
28
29    /// A system call failed.
30    #[error("System call error: {0}")]
31    SystemCall(String),
32
33    /// The connection was closed by the peer.
34    #[error("Connection closed")]
35    ConnectionClosed,
36
37    /// The message format was invalid.
38    #[error("Invalid message format: {0}")]
39    InvalidMessage(String),
40}
41
42/// A specialized Result type for JSON-RPC operations.
43pub type Result<T> = std::result::Result<T, Error>;