Skip to content

Commit 9838f5d

Browse files
committed
re-add missing errors
1 parent bc24fd0 commit 9838f5d

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

src/eth.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,14 @@ pub enum EthError {
8080
SubscriptionClosed(u64),
8181
/// Invalid method
8282
InvalidMethod(String),
83+
/// Invalid parameters
84+
InvalidParams,
8385
/// Permission denied
8486
PermissionDenied,
8587
/// RPC timed out
8688
RpcTimeout,
89+
/// RPC gave garbage back
90+
RpcMalformedResponse,
8791
}
8892

8993
/// The action type used for configuring eth:distro:sys. Only processes which have the "root"
@@ -201,16 +205,14 @@ impl Provider {
201205
.map_err(|_| EthError::RpcTimeout)?;
202206

203207
match resp {
204-
Message::Response { body, .. } => {
205-
let response = serde_json::from_slice::<EthResponse>(&body);
206-
match response {
207-
Ok(EthResponse::Response { value }) => serde_json::from_value::<T>(value)
208-
.map_err(|e| EthError::RpcError(format!("{e:?}"))),
209-
Ok(EthResponse::Err(e)) => Err(e),
210-
_ => Err(EthError::RpcError("unexpected response".to_string())),
208+
Message::Response { body, .. } => match serde_json::from_slice::<EthResponse>(&body) {
209+
Ok(EthResponse::Response { value }) => {
210+
serde_json::from_value::<T>(value).map_err(|_| EthError::RpcMalformedResponse)
211211
}
212-
}
213-
_ => Err(EthError::RpcError("unexpected response".to_string())),
212+
Ok(EthResponse::Err(e)) => Err(e),
213+
_ => Err(EthError::RpcMalformedResponse),
214+
},
215+
_ => Err(EthError::RpcMalformedResponse),
214216
}
215217
}
216218

@@ -593,10 +595,10 @@ impl Provider {
593595
match response {
594596
Ok(EthResponse::Ok) => Ok(()),
595597
Ok(EthResponse::Err(e)) => Err(e),
596-
_ => Err(EthError::RpcError("unexpected response".to_string())),
598+
_ => Err(EthError::RpcMalformedResponse),
597599
}
598600
}
599-
_ => Err(EthError::RpcError("unexpected response".to_string())),
601+
_ => Err(EthError::RpcMalformedResponse),
600602
}
601603
}
602604

@@ -606,27 +608,23 @@ impl Provider {
606608
/// - `sub_id`: The subscription ID to unsubscribe from.
607609
///
608610
/// # Returns
609-
/// An `anyhow::Result<()>` indicating whether the subscription was cancelled.
610-
pub fn unsubscribe(&self, sub_id: u64) -> anyhow::Result<()> {
611+
/// A `Result<(), EthError>` indicating whether the subscription was cancelled.
612+
pub fn unsubscribe(&self, sub_id: u64) -> Result<(), EthError> {
611613
let action = EthAction::UnsubscribeLogs(sub_id);
612614

613615
let resp = KiRequest::new()
614616
.target(("our", "eth", "distro", "sys"))
615-
.body(serde_json::to_vec(&action)?)
616-
.send_and_await_response(self.request_timeout)??;
617+
.body(serde_json::to_vec(&action).map_err(|_| EthError::MalformedRequest)?)
618+
.send_and_await_response(self.request_timeout)
619+
.unwrap()
620+
.map_err(|_| EthError::RpcTimeout)?;
617621

618622
match resp {
619-
Message::Response { body, .. } => {
620-
let response = serde_json::from_slice::<EthResponse>(&body)?;
621-
match response {
622-
EthResponse::Ok => Ok(()),
623-
EthResponse::Response { .. } => {
624-
Err(anyhow::anyhow!("unexpected response: {:?}", response))
625-
}
626-
EthResponse::Err(e) => Err(anyhow::anyhow!("{e:?}")),
627-
}
628-
}
629-
_ => Err(anyhow::anyhow!("unexpected message type: {:?}", resp)),
623+
Message::Response { body, .. } => match serde_json::from_slice::<EthResponse>(&body) {
624+
Ok(EthResponse::Ok) => Ok(()),
625+
_ => Err(EthError::RpcMalformedResponse),
626+
},
627+
_ => Err(EthError::RpcMalformedResponse),
630628
}
631629
}
632630
}

0 commit comments

Comments
 (0)