diff --git a/crates/agent/src/rpc/control.rs b/crates/agent/src/rpc/control.rs index 285a7a1c..85cd181f 100644 --- a/crates/agent/src/rpc/control.rs +++ b/crates/agent/src/rpc/control.rs @@ -177,7 +177,7 @@ impl AgentService for AgentRpcServer { .state .get_env_info(env_id) .await - .map_err(|_| AgentError::FailedToMakeRequest)? + .map_err(|e| AgentError::FailedToGetEnvInfo(e.to_string()))? .network; let url = format!( @@ -186,26 +186,31 @@ impl AgentService for AgentRpcServer { self.state.cli.ports.rest ); let response = reqwest::Client::new() - .post(url) + .post(&url) .header("Content-Type", "application/json") .body(tx) .send() .await - .map_err(|_| AgentError::FailedToMakeRequest)?; + .map_err(|e| AgentError::FailedToMakeRequest(format!("{url}: {e:?}")))?; let status = response.status(); if status.is_success() { - Ok(()) + return Ok(()); // transaction already exists so this is technically a success - } else if status.is_server_error() - && response - .text() - .await - .ok() + } + + let text = response.text().await.ok(); + + if status.is_server_error() + && text + .as_ref() .is_some_and(|text| text.contains("exists in the ledger")) { - return Ok(()); + Ok(()) } else { - Err(AgentError::FailedToMakeRequest) + Err(AgentError::FailedToMakeRequest(format!( + "{url}: {status:?} {}", + text.unwrap_or_else(|| "no error message".to_string()) + ))) } } @@ -329,7 +334,7 @@ impl AgentService for AgentRpcServer { .ok_or(AgentError::NodeClientNotSet)? .get_block_lite(ctx, block_hash) .await - .map_err(|_| AgentError::FailedToMakeRequest)? + .map_err(|e| AgentError::FailedToMakeRequest(format!("block info: {e:?}")))? } async fn find_transaction( @@ -343,7 +348,7 @@ impl AgentService for AgentRpcServer { .ok_or(AgentError::NodeClientNotSet)? .find_transaction(context, tx_id) .await - .map_err(|_| AgentError::FailedToMakeRequest)? + .map_err(|e| AgentError::FailedToMakeRequest(format!("find tx: {e:?}")))? } async fn get_status(self, ctx: Context) -> Result { diff --git a/crates/aot/src/runner/rpc/node.rs b/crates/aot/src/runner/rpc/node.rs index 924c8653..451705ee 100644 --- a/crates/aot/src/runner/rpc/node.rs +++ b/crates/aot/src/runner/rpc/node.rs @@ -62,7 +62,9 @@ impl NodeService for NodeRpcServer { block_db .find_block_hash(&tx_id) - .map_err(|_| AgentError::FailedToMakeRequest) + .map_err(|e| { + AgentError::FailedToMakeRequest(format!("block hash for tx {tx_id}: {e:?}")) + }) .map(|hash| hash.map(|hash| hash.to_string())) } @@ -80,9 +82,9 @@ impl NodeService for NodeRpcServer { .parse() .map_err(|_| AgentError::InvalidBlockHash)?; - let Some(height) = block_db - .get_block_height(&hash) - .map_err(|_| AgentError::FailedToMakeRequest)? + let Some(height) = block_db.get_block_height(&hash).map_err(|e| { + AgentError::FailedToMakeRequest(format!("block height for hash {hash}: {e:?}")) + })? else { return Ok(None); }; @@ -91,9 +93,9 @@ impl NodeService for NodeRpcServer { return Ok(None); }; - let Some(transactions) = block_db - .get_block_transactions(&hash) - .map_err(|_| AgentError::FailedToMakeRequest)? + let Some(transactions) = block_db.get_block_transactions(&hash).map_err(|e| { + AgentError::FailedToMakeRequest(format!("transactions for height {height}: {e:?}")) + })? else { return Ok(None); }; diff --git a/crates/common/src/rpc/error.rs b/crates/common/src/rpc/error.rs index 3a6ecb24..4977c33a 100644 --- a/crates/common/src/rpc/error.rs +++ b/crates/common/src/rpc/error.rs @@ -70,8 +70,8 @@ pub enum AgentError { InvalidState, #[error("failed to parse json")] FailedToParseJson, - #[error("failed to make a request")] - FailedToMakeRequest, + #[error("failed to make a request: {0}")] + FailedToMakeRequest(String), #[error("failed to get env info: {0}")] FailedToGetEnvInfo(String), #[error("failed to spawn a process")] diff --git a/crates/controlplane/src/cannon/context.rs b/crates/controlplane/src/cannon/context.rs index 13833bc8..33e89014 100644 --- a/crates/controlplane/src/cannon/context.rs +++ b/crates/controlplane/src/cannon/context.rs @@ -308,7 +308,7 @@ impl ExecutionContext { }; if let Err(e) = client.broadcast_tx(tx_str.clone()).await { - warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to agent {id}: {e}"); + warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to agent {id}: {e:?}"); continue; } @@ -332,7 +332,7 @@ impl ExecutionContext { match res { Err(e) => { - warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {e}"); + warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {e:?}"); continue; } Ok(req) => { @@ -350,7 +350,7 @@ impl ExecutionContext { return Ok(tx_id); } - warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {}", status); + warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {status}"); continue; } }