diff --git a/offchain/advance-runner/src/server_manager/facade.rs b/offchain/advance-runner/src/server_manager/facade.rs index 8596cdbdd..5ebe0bcc0 100644 --- a/offchain/advance-runner/src/server_manager/facade.rs +++ b/offchain/advance-runner/src/server_manager/facade.rs @@ -199,7 +199,7 @@ impl ServerManagerFacade { } }); - self.handle_advance_state_error(response).await; + self.handle_advance_state_error(response).await?; tracing::trace!("waiting until the input is processed"); @@ -278,14 +278,18 @@ impl ServerManagerFacade { async fn handle_advance_state_error( &mut self, response: Result, - ) { - // Capture server-manager error for advance-state request - // to try to get the reason for a possible tainted session error. - if response.is_err() { - match response.unwrap_err() { + ) -> Result<()> { + if response.is_ok() { + Ok(()) + } else { + // Capture server-manager error for advance-state request + // to try to get the reason for a possible tainted session error. + let err = response.unwrap_err(); + + let err: ServerManagerError = match err { ServerManagerError::MethodCallError { - method: _, - request_id: _, + method, + request_id, source, } => { // Original error message to be reported by default. @@ -309,17 +313,34 @@ impl ServerManagerFacade { request_id: _, source, } => { - message = format!("Server manager session was tainted: {} ({})", source.code(), source.message()); + tracing::error!( + "get-session-status error: {:?}", + source.message() + ); } _ => {} } } else { + let status_response = status_response.unwrap(); + let taint_status = + status_response.taint_status.clone(); + if let Some(taint_status) = taint_status { + message = format!("Server manager session was tainted: {} ({})", + taint_status.error_code, + taint_status.error_message); + tracing::error!(message); + } } } - tracing::error!(message); + ServerManagerError::MethodCallError { + method, + request_id, + source: tonic::Status::new(source.code(), message), + } } - _ => {} - } + _ => err, + }; + Err(err) } } @@ -421,3 +442,15 @@ impl ServerManagerFacade { Err(ServerManagerError::PendingInputsExceededError {}) } } + +#[tracing::instrument(level = "trace", skip_all)] +fn get_advance_state_error_message(err: &ServerManagerError) -> Option { + match err { + ServerManagerError::MethodCallError { + method: _, + request_id: _, + source, + } => Some(source.message().to_string()), + _ => None, + } +} diff --git a/offchain/advance-runner/tests/host_integration.rs b/offchain/advance-runner/tests/host_integration.rs index c1c090a07..2604c3078 100644 --- a/offchain/advance-runner/tests/host_integration.rs +++ b/offchain/advance-runner/tests/host_integration.rs @@ -116,7 +116,7 @@ async fn advance_runner_fails_when_inputs_has_wrong_epoch() { tracing::info!("waiting for the advance_runner to exit with error"); let err = state.advance_runner.wait_err().await; - assert!(format!("{:?}", err).contains("unknown epoch index")); + assert!(format!("{:?}", err).contains("incorrect active epoch index")); } #[test_log::test(tokio::test)]