diff --git a/ethers-providers/src/transports/common.rs b/ethers-providers/src/transports/common.rs index 2afdecba..50fe280a 100644 --- a/ethers-providers/src/transports/common.rs +++ b/ethers-providers/src/transports/common.rs @@ -82,6 +82,16 @@ impl ResponseData { } } +impl ResponseData { + /// Encode the error to json value if it is an error + pub fn into_value(self) -> serde_json::Result { + match self { + ResponseData::Success { result } => Ok(result), + ResponseData::Error { error } => serde_json::to_value(error), + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/ethers-providers/src/transports/ipc.rs b/ethers-providers/src/transports/ipc.rs index a61bb862..ae8d234f 100644 --- a/ethers-providers/src/transports/ipc.rs +++ b/ethers-providers/src/transports/ipc.rs @@ -181,7 +181,7 @@ where }, // Handle socket messages msg = self.socket_reader.next() => match msg { - Some(Ok(msg)) => self.handle_socket(read_buffer, msg).await?, + Some(Ok(msg)) => self.handle_socket(read_buffer, msg)?, Some(Err(err)) => { error!("IPC read error: {:?}", err); return Err(err.into()); @@ -207,7 +207,7 @@ where } if let Err(err) = self.socket_writer.write(request.as_bytes()).await { - error!("WS connection error: {:?}", err); + error!("IPC connection error: {:?}", err); self.pending.remove(&id); } } @@ -229,7 +229,7 @@ where Ok(()) } - async fn handle_socket( + fn handle_socket( &mut self, read_buffer: &mut Vec, bytes: bytes::Bytes, @@ -292,7 +292,7 @@ where let id = output.id; // Converts output into result, to send data if valid response. - let value = output.data.into_result()?; + let value = output.data.into_value()?; let response_tx = self.pending.remove(&id).ok_or_else(|| { IpcError::ChannelError("No response channel exists for the response ID".to_string())