Skip to content

Commit

Permalink
fixup! feat(advance-runner): log tainted session reason
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstanley committed Aug 22, 2024
1 parent 7ae488b commit 06cac80
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
57 changes: 45 additions & 12 deletions offchain/advance-runner/src/server_manager/facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -278,14 +278,18 @@ impl ServerManagerFacade {
async fn handle_advance_state_error(
&mut self,
response: Result<grpc_interfaces::cartesi_machine::Void>,
) {
// 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.
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -421,3 +442,15 @@ impl ServerManagerFacade {
Err(ServerManagerError::PendingInputsExceededError {})
}
}

#[tracing::instrument(level = "trace", skip_all)]
fn get_advance_state_error_message(err: &ServerManagerError) -> Option<String> {
match err {
ServerManagerError::MethodCallError {
method: _,
request_id: _,
source,
} => Some(source.message().to_string()),
_ => None,
}
}
2 changes: 1 addition & 1 deletion offchain/advance-runner/tests/host_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 06cac80

Please sign in to comment.