Skip to main content

trustless_protocol/
error.rs

1/// Error types for protocol operations.
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    /// An I/O error occurred on the underlying stream.
5    #[error("io error: {0}")]
6    Io(#[from] std::io::Error),
7
8    /// JSON serialization or deserialization failed.
9    #[error("json error: {0}")]
10    Json(#[from] serde_json::Error),
11
12    /// The provider returned an error response.
13    #[error(transparent)]
14    Provider(#[from] crate::message::ErrorCode),
15
16    /// The response ID did not match the request ID.
17    #[error("unexpected response id: expected {expected}, got {got}")]
18    UnexpectedResponseId { expected: u64, got: u64 },
19
20    /// The response method did not match what was expected.
21    #[error("unexpected response method")]
22    UnexpectedResponseMethod,
23
24    /// The provider process exited (stdin/stdout reached EOF).
25    #[error("provider process exited unexpectedly")]
26    ProcessExited,
27}
28
29impl From<crate::message::ErrorPayload> for Error {
30    fn from(p: crate::message::ErrorPayload) -> Self {
31        Error::Provider(crate::message::ErrorCode::from(p))
32    }
33}