Fix lossy error propagation in consensus (#8156)

Co-authored-by: leohenon <77656081+lhenon999@users.noreply.github.com>
This commit is contained in:
Leo Henon
2026-02-18 17:21:05 +01:00
committed by timvisee
co-authored by leohenon
parent 35d84709f9
commit 2c1182542c
+9 -11
View File
@@ -226,7 +226,7 @@ impl Consensus {
&runtime,
leader_established_in_ms,
)
.map_err(|err| anyhow!("Failed to initialize Consensus for new Raft state: {err}"))?;
.context("Failed to initialize Consensus for new Raft state")?;
} else {
runtime
.block_on(Self::recover(
@@ -236,9 +236,7 @@ impl Consensus {
&config,
tls_config.clone(),
))
.map_err(|err| {
anyhow!("Failed to recover Consensus from existing Raft state: {err}")
})?;
.context("Failed to recover Consensus from existing Raft state")?;
if bootstrap_peer.is_some() || uri.is_some() {
log::debug!("Local raft state found - bootstrap and uri cli arguments were ignored")
@@ -341,7 +339,7 @@ impl Consensus {
tls_config,
)
.await
.map_err(|err| anyhow!("Failed to create timeout channel: {err}"))?;
.context("Failed to create timeout channel")?;
let mut client = RaftClient::new(channel);
let all_peers = client
.add_peer_to_known(tonic::Request::new(
@@ -352,7 +350,7 @@ impl Consensus {
},
))
.await
.map_err(|err| anyhow!("Failed to add peer to known: {err}"))?
.context("Failed to add peer to known")?
.into_inner();
Ok(all_peers)
}
@@ -455,7 +453,7 @@ impl Consensus {
.parse()
.context(format!("Failed to parse peer URI: {}", peer.uri))?,
)
.map_err(|err| anyhow!("Failed to add peer: {err}"))?
.context("Failed to add peer")?
}
// Only first peer has itself as a voter in the initial conf state.
// This needs to be propagated manually to other peers as it is not contained in any log entry.
@@ -946,7 +944,7 @@ impl Consensus {
store
.append_entries(ready.take_entries())
.map_err(|err| anyhow!("Failed to append entries: {err}"))?
.context("Failed to append entries")?
}
if let Some(hs) = ready.hs() {
@@ -956,7 +954,7 @@ impl Consensus {
store
.set_hard_state(hs.clone())
.map_err(|err| anyhow!("Failed to set hard state: {err}"))?
.context("Failed to set hard state")?
}
let role_change = ready.ss().map(|ss| ss.raft_state);
@@ -1019,7 +1017,7 @@ impl Consensus {
store
.set_commit_index(commit)
.map_err(|err| anyhow!("Failed to set commit index: {err}"))?;
.context("Failed to set commit index")?;
}
self.send_messages(light_rd.take_messages());
@@ -1416,7 +1414,7 @@ impl RaftMessageSender {
self.tls_config.clone(),
)
.await
.map_err(|err| anyhow::format_err!("Failed to create who-is channel: {err}"))?;
.context("Failed to create who-is channel")?;
let uri = RaftClient::new(channel)
.who_is(tonic::Request::new(GrpcPeerId { id: peer_id }))