1use std::time::Duration;
2
3#[derive(thiserror::Error, Debug, Clone, PartialEq)]
5pub enum WireError {
6 #[error("wire stream closed")]
8 StreamClosed,
9
10 #[error("wire I/O timed out after {0:?}")]
12 Timeout(Duration),
13
14 #[error("failed to spawn process: {0}")]
16 SpawnFailed(String),
17
18 #[error("JSON parse error: {0}")]
20 JsonParse(String),
21
22 #[error("JSON serialization error: {0}")]
24 JsonSerialize(String),
25
26 #[error("wire request failed: {message} (code: {code})")]
29 RequestFailed {
30 code: i32,
32 message: String,
34 },
35
36 #[error("unexpected response id: expected {expected}, got {got}")]
39 UnexpectedResponseId {
40 expected: String,
42 got: String,
44 },
45
46 #[error("method not found: {0}")]
48 MethodNotFound(String),
49
50 #[error("unknown wire message type: {0}")]
52 UnknownMessageType(String),
53
54 #[error("wire message payload must be a JSON object")]
56 InvalidPayloadType,
57
58 #[error("I/O error: {0}")]
60 Io(String),
61
62 #[error("internal error: {0}")]
64 Internal(String),
65}
66
67impl From<std::io::Error> for WireError {
68 fn from(err: std::io::Error) -> Self {
69 WireError::Io(err.to_string())
70 }
71}
72
73impl From<serde_json::Error> for WireError {
74 fn from(err: serde_json::Error) -> Self {
75 if err.is_io() {
76 WireError::Io(err.to_string())
77 } else {
78 WireError::JsonParse(err.to_string())
79 }
80 }
81}