From cbe5fb58f4cb2bc5b86355afe085e0e49ef40cac Mon Sep 17 00:00:00 2001 From: uriel-starkware <162032630+uriel-starkware@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:25:25 +0300 Subject: [PATCH] chore: add a represantation of unxepected enum in client error (#158) --- .../src/component_client/definitions.rs | 4 ++-- .../tests/component_server_client_http_test.rs | 8 ++++++-- .../tests/component_server_client_test.rs | 8 ++++++-- crates/mempool_types/src/communication.rs | 16 ++++++++++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/mempool_infra/src/component_client/definitions.rs b/crates/mempool_infra/src/component_client/definitions.rs index 93cdbfa7d3..8b4c82a50d 100644 --- a/crates/mempool_infra/src/component_client/definitions.rs +++ b/crates/mempool_infra/src/component_client/definitions.rs @@ -14,8 +14,8 @@ pub enum ClientError { ResponseParsingFailure(HyperError), #[error("Got status code: {0}, with server error: {1}")] ResponseError(StatusCode, ServerError), - #[error("Got an unexpected response type.")] - UnexpectedResponse, + #[error("Got an unexpected response type: {0}")] + UnexpectedResponse(String), } pub type ClientResult = Result; diff --git a/crates/mempool_infra/tests/component_server_client_http_test.rs b/crates/mempool_infra/tests/component_server_client_http_test.rs index 2febdf8710..c1b6d9ddea 100644 --- a/crates/mempool_infra/tests/component_server_client_http_test.rs +++ b/crates/mempool_infra/tests/component_server_client_http_test.rs @@ -72,14 +72,18 @@ impl ComponentBClientTrait for RemoteComponentClient ResultB { match self.send(ComponentBRequest::BGetValue).await? { ComponentBResponse::BGetValue(value) => Ok(value), - _ => Err(ClientError::UnexpectedResponse), + unexpected_response => { + Err(ClientError::UnexpectedResponse(format!("{unexpected_response:?}"))) + } } } async fn b_set_value(&self, value: ValueB) -> ClientResult<()> { match self.send(ComponentBRequest::BSetValue(value)).await? { ComponentBResponse::BSetValue => Ok(()), - _ => Err(ClientError::UnexpectedResponse), + unexpected_response => { + Err(ClientError::UnexpectedResponse(format!("{unexpected_response:?}"))) + } } } } diff --git a/crates/mempool_infra/tests/component_server_client_test.rs b/crates/mempool_infra/tests/component_server_client_test.rs index 7766fc6d44..1430b36e89 100644 --- a/crates/mempool_infra/tests/component_server_client_test.rs +++ b/crates/mempool_infra/tests/component_server_client_test.rs @@ -52,14 +52,18 @@ impl ComponentBClientTrait for LocalComponentClient Ok(value), - _ => Err(ClientError::UnexpectedResponse), + unexpected_response => { + Err(ClientError::UnexpectedResponse(format!("{unexpected_response:?}"))) + } } } async fn b_set_value(&self, value: ValueB) -> ClientResult<()> { match self.send(ComponentBRequest::BSetValue(value)).await { ComponentBResponse::BSetValue => Ok(()), - _ => Err(ClientError::UnexpectedResponse), + unexpected_response => { + Err(ClientError::UnexpectedResponse(format!("{unexpected_response:?}"))) + } } } } diff --git a/crates/mempool_types/src/communication.rs b/crates/mempool_types/src/communication.rs index d17e54368d..0bb8c5aaa2 100644 --- a/crates/mempool_types/src/communication.rs +++ b/crates/mempool_types/src/communication.rs @@ -62,7 +62,9 @@ impl MempoolClient for MempoolClientImpl { MempoolResponse::AddTransaction(Err(response)) => { Err(MempoolClientError::MempoolError(response)) } - _ => Err(MempoolClientError::ClientError(ClientError::UnexpectedResponse)), + unexpected_response => Err(MempoolClientError::ClientError( + ClientError::UnexpectedResponse(format!("{unexpected_response:?}")), + )), } } @@ -74,7 +76,9 @@ impl MempoolClient for MempoolClientImpl { MempoolResponse::GetTransactions(Err(response)) => { Err(MempoolClientError::MempoolError(response)) } - _ => Err(MempoolClientError::ClientError(ClientError::UnexpectedResponse)), + unexpected_response => Err(MempoolClientError::ClientError( + ClientError::UnexpectedResponse(format!("{unexpected_response:?}")), + )), } } } @@ -89,7 +93,9 @@ impl MempoolClient for RemoteMempoolClientImpl { MempoolResponse::AddTransaction(Err(response)) => { Err(MempoolClientError::MempoolError(response)) } - _ => Err(MempoolClientError::ClientError(ClientError::UnexpectedResponse)), + unexpected_response => Err(MempoolClientError::ClientError( + ClientError::UnexpectedResponse(format!("{unexpected_response:?}")), + )), } } @@ -101,7 +107,9 @@ impl MempoolClient for RemoteMempoolClientImpl { MempoolResponse::GetTransactions(Err(response)) => { Err(MempoolClientError::MempoolError(response)) } - _ => Err(MempoolClientError::ClientError(ClientError::UnexpectedResponse)), + unexpected_response => Err(MempoolClientError::ClientError( + ClientError::UnexpectedResponse(format!("{unexpected_response:?}")), + )), } } }