From f841587c27342fb41b63cfef3dfb8148d836f4fc Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 15 Aug 2022 22:40:54 +0800 Subject: [PATCH] chore: add log --- frontend/rust-lib/flowy-error/src/errors.rs | 2 ++ .../flowy-folder/src/services/app/controller.rs | 4 +++- .../flowy-folder/src/services/app/event_handler.rs | 2 +- frontend/rust-lib/flowy-test/src/event_builder.rs | 14 ++++++++++---- .../rust-lib/flowy-user/src/services/database.rs | 2 +- frontend/rust-lib/lib-dispatch/src/byte_trait.rs | 7 ++++++- frontend/rust-lib/lib-dispatch/src/data.rs | 11 +++++++++-- frontend/rust-lib/lib-dispatch/src/dispatcher.rs | 12 +++++++----- 8 files changed, 39 insertions(+), 15 deletions(-) diff --git a/frontend/rust-lib/flowy-error/src/errors.rs b/frontend/rust-lib/flowy-error/src/errors.rs index cd890fd02e..e19ebb15b2 100644 --- a/frontend/rust-lib/flowy-error/src/errors.rs +++ b/frontend/rust-lib/flowy-error/src/errors.rs @@ -93,6 +93,8 @@ impl fmt::Display for FlowyError { impl lib_dispatch::Error for FlowyError { fn as_response(&self) -> EventResponse { let bytes: Bytes = self.clone().try_into().unwrap(); + + println!("Serialize FlowyError: {:?} to event response", self); ResponseBuilder::Err().data(bytes).build() } } diff --git a/frontend/rust-lib/flowy-folder/src/services/app/controller.rs b/frontend/rust-lib/flowy-folder/src/services/app/controller.rs index 112ad052ce..375e696bd1 100644 --- a/frontend/rust-lib/flowy-folder/src/services/app/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/app/controller.rs @@ -68,7 +68,9 @@ impl AppController { let app = transaction.read_app(¶ms.value)?; let trash_ids = self.trash_controller.read_trash_ids(&transaction)?; if trash_ids.contains(&app.id) { - return Err(FlowyError::record_not_found()); + return Err( + FlowyError::record_not_found().context(format!("Can not find the app:{}", params.value)) + ); } Ok(app) }) diff --git a/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs index e2087c167e..1594351015 100644 --- a/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs +++ b/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs @@ -44,7 +44,7 @@ pub(crate) async fn update_app_handler( Ok(()) } -#[tracing::instrument(level = "trace", skip(data, app_controller, view_controller))] +#[tracing::instrument(level = "info", skip(data, app_controller, view_controller), err)] pub(crate) async fn read_app_handler( data: Data, app_controller: AppData>, diff --git a/frontend/rust-lib/flowy-test/src/event_builder.rs b/frontend/rust-lib/flowy-test/src/event_builder.rs index d6f42ecf31..75cdff5f38 100644 --- a/frontend/rust-lib/flowy-test/src/event_builder.rs +++ b/frontend/rust-lib/flowy-test/src/event_builder.rs @@ -83,15 +83,21 @@ where R: FromBytes, { let response = self.get_response(); - match response.parse::() { + match response.clone().parse::() { Ok(Ok(data)) => data, Ok(Err(e)) => { - panic!("Parser {:?} failed: {:?}", std::any::type_name::(), e) + panic!( + "Parser {:?} failed: {:?}, response {:?}", + std::any::type_name::(), + e, + response + ) } Err(e) => panic!( - "Internal error: {:?}, parser {:?} failed", - e, + "Dispatch {:?} failed: {:?}, response {:?}", std::any::type_name::(), + e, + response ), } } diff --git a/frontend/rust-lib/flowy-user/src/services/database.rs b/frontend/rust-lib/flowy-user/src/services/database.rs index 62b74c9f22..9e94ea2c9d 100644 --- a/frontend/rust-lib/flowy-user/src/services/database.rs +++ b/frontend/rust-lib/flowy-user/src/services/database.rs @@ -37,8 +37,8 @@ impl UserDB { Some(database) => return Ok(database.get_pool()), } - tracing::trace!("open user db {}", user_id); let dir = format!("{}/{}", self.db_dir, user_id); + tracing::trace!("open user db {} at path: {}", user_id, dir); let db = flowy_database::init(&dir).map_err(|e| { log::error!("open user: {} db failed, {:?}", user_id, e); FlowyError::internal().context(e) diff --git a/frontend/rust-lib/lib-dispatch/src/byte_trait.rs b/frontend/rust-lib/lib-dispatch/src/byte_trait.rs index 9f8c2a6545..0e48813afd 100644 --- a/frontend/rust-lib/lib-dispatch/src/byte_trait.rs +++ b/frontend/rust-lib/lib-dispatch/src/byte_trait.rs @@ -14,7 +14,12 @@ where fn into_bytes(self) -> Result { match self.try_into() { Ok(data) => Ok(data), - Err(e) => Err(InternalError::ProtobufError(format!("{:?}", e)).into()), + Err(e) => Err(InternalError::ProtobufError(format!( + "Serial {:?} to bytes failed:{:?}", + std::any::type_name::(), + e + )) + .into()), } } } diff --git a/frontend/rust-lib/lib-dispatch/src/data.rs b/frontend/rust-lib/lib-dispatch/src/data.rs index e331fe071e..15f9684a16 100644 --- a/frontend/rust-lib/lib-dispatch/src/data.rs +++ b/frontend/rust-lib/lib-dispatch/src/data.rs @@ -55,7 +55,10 @@ where { fn respond_to(self, _request: &EventRequest) -> EventResponse { match self.into_inner().into_bytes() { - Ok(bytes) => ResponseBuilder::Ok().data(bytes).build(), + Ok(bytes) => { + log::trace!("Serialize Data: {:?} to event response", std::any::type_name::()); + return ResponseBuilder::Ok().data(bytes).build(); + } Err(e) => e.into(), } } @@ -86,7 +89,11 @@ where T: FromBytes, { match payload { - Payload::None => Err(InternalError::UnexpectedNone("Parse fail, expected payload".to_string()).into()), + Payload::None => Err(InternalError::UnexpectedNone(format!( + "Parse fail, expected payload:{:?}", + std::any::type_name::() + )) + .into()), Payload::Bytes(bytes) => { let data = T::parse_from_bytes(bytes.clone())?; Ok(Data(data)) diff --git a/frontend/rust-lib/lib-dispatch/src/dispatcher.rs b/frontend/rust-lib/lib-dispatch/src/dispatcher.rs index fd7296a70d..961f19986b 100644 --- a/frontend/rust-lib/lib-dispatch/src/dispatcher.rs +++ b/frontend/rust-lib/lib-dispatch/src/dispatcher.rs @@ -54,16 +54,18 @@ impl EventDispatcher { callback: Some(Box::new(callback)), }; let join_handle = dispatch.runtime.spawn(async move { - service - .call(service_ctx) - .await - .unwrap_or_else(|e| InternalError::Other(format!("{:?}", e)).as_response()) + service.call(service_ctx).await.unwrap_or_else(|e| { + tracing::error!("Dispatch runtime error: {:?}", e); + InternalError::Other(format!("{:?}", e)).as_response() + }) }); DispatchFuture { fut: Box::pin(async move { join_handle.await.unwrap_or_else(|e| { - let error = InternalError::JoinError(format!("EVENT_DISPATCH join error: {:?}", e)); + let msg = format!("EVENT_DISPATCH join error: {:?}", e); + tracing::error!("{}", msg); + let error = InternalError::JoinError(msg); error.as_response() }) }),