From a857823099f7b4c6e0a9a6f92e156ceffb0ba5ad Mon Sep 17 00:00:00 2001 From: Al Liu Date: Sun, 12 Nov 2023 20:48:22 +0800 Subject: [PATCH] Fix PR comments --- nodes/nomos-node-api/src/lib.rs | 5 ++--- nomos-services/http/src/http.rs | 23 +++++------------------ nomos-services/storage/src/lib.rs | 2 +- nomos-services/system-sig/src/lib.rs | 3 +-- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/nodes/nomos-node-api/src/lib.rs b/nodes/nomos-node-api/src/lib.rs index 695be9e0..877c4cde 100644 --- a/nodes/nomos-node-api/src/lib.rs +++ b/nodes/nomos-node-api/src/lib.rs @@ -65,11 +65,10 @@ where async fn run(mut self) -> Result<(), ServiceError> { let endpoint = B::new(self.settings.backend_settings) .await - .map_err(|e| Box::new(e) as DynError)?; + .map_err(ServiceError::service)?; endpoint .serve(self.handle) .await - .map_err(|e| Box::new(e) as DynError)?; - Ok(()) + .map_err(ServiceError::service) } } diff --git a/nomos-services/http/src/http.rs b/nomos-services/http/src/http.rs index fafa89fb..55334868 100644 --- a/nomos-services/http/src/http.rs +++ b/nomos-services/http/src/http.rs @@ -131,7 +131,7 @@ where backend, inbound_relay, }) - .map_err(|e| ServiceError::Service(Box::new(e))) + .map_err(ServiceError::service) } async fn run(mut self) -> Result<(), ServiceError> { @@ -195,25 +195,12 @@ where oneshot::Sender, ) -> Result, { - #[derive(Debug)] - struct EmptyPayload; - - impl core::fmt::Display for EmptyPayload { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "empty payload") - } - } - - impl Error for EmptyPayload {} - - let payload = payload - .ok_or(EmptyPayload) - .map_err(|e| ServiceError::Service(Box::new(e)))?; + let payload = payload.ok_or(ServiceError::custom("empty payload"))?; let req = async_graphql::http::receive_batch_json(&payload[..]) .await - .map_err(|e| ServiceError::Service(Box::new(e)))? + .map_err(ServiceError::service)? .into_single() - .map_err(|e| ServiceError::Service(Box::new(e)))?; + .map_err(ServiceError::service)?; let (sender, receiver) = oneshot::channel(); relay @@ -226,6 +213,6 @@ where .map_err(|e| ServiceError::RelayError(e.0))?; let res = receiver.await.unwrap(); - let res = serde_json::to_string(&res).map_err(|e| ServiceError::Service(Box::new(e)))?; + let res = serde_json::to_string(&res).map_err(ServiceError::service)?; Ok(res) } diff --git a/nomos-services/storage/src/lib.rs b/nomos-services/storage/src/lib.rs index 55a5ceb7..57a56726 100644 --- a/nomos-services/storage/src/lib.rs +++ b/nomos-services/storage/src/lib.rs @@ -276,7 +276,7 @@ impl ServiceCore for StorageSer fn init(service_state: ServiceStateHandle) -> Result { Ok(Self { backend: Backend::new(service_state.settings_reader.get_updated_settings()) - .map_err(|e| ServiceError::Service(Box::new(e)))?, + .map_err(ServiceError::service)?, service_state, }) } diff --git a/nomos-services/system-sig/src/lib.rs b/nomos-services/system-sig/src/lib.rs index a7d9e3ef..c86d3839 100644 --- a/nomos-services/system-sig/src/lib.rs +++ b/nomos-services/system-sig/src/lib.rs @@ -53,8 +53,7 @@ impl ServiceCore for SystemSig { async fn run(self) -> Result<(), ServiceError> { let Self { service_state } = self; - let mut ctrlc = - async_ctrlc::CtrlC::new().map_err(|e| ServiceError::Service(Box::new(e)))?; + let mut ctrlc = async_ctrlc::CtrlC::new().map_err(ServiceError::service)?; let mut lifecycle_stream = service_state.lifecycle_handle.message_stream(); loop { tokio::select! {