Skip to content

Commit 926bf6d

Browse files
committed
Change: Remove RemoteError variant from StreamingError
`StreamingError` is intended to represent non-logic errors that occur while streaming data to a remote peer. A `RemoteError` does not belong in a stream RPC error and should instead be included as part of a non-error response. Upgrade tip: No modifications are required for this change, as no related API utilized the `RemoteError` variant.
1 parent 40e5b1a commit 926bf6d

File tree

2 files changed

+6
-61
lines changed

2 files changed

+6
-61
lines changed

openraft/src/error/decompose.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::error::Error;
22

33
use crate::error::into_ok::into_ok;
4-
use crate::error::Fatal;
54
use crate::error::Infallible;
65
use crate::error::RPCError;
76
use crate::error::RaftError;
8-
use crate::error::StreamingError;
97
use crate::error::Unreachable;
108
use crate::RaftTypeConfig;
119

@@ -72,24 +70,3 @@ where
7270
}
7371
}
7472
}
75-
76-
impl<C, R> DecomposeResult<C, R, StreamingError<C>> for Result<R, StreamingError<C, Fatal<C>>>
77-
where C: RaftTypeConfig
78-
{
79-
type InnerError = Infallible;
80-
81-
/// `Fatal` is considered as `RPCError::Unreachable`.
82-
fn decompose(self) -> Result<Result<R, Self::InnerError>, StreamingError<C>> {
83-
match self {
84-
Ok(r) => Ok(Ok(r)),
85-
Err(e) => match e {
86-
StreamingError::Closed(e) => Err(StreamingError::Closed(e)),
87-
StreamingError::StorageError(e) => Err(StreamingError::StorageError(e)),
88-
StreamingError::Timeout(e) => Err(StreamingError::Timeout(e)),
89-
StreamingError::Unreachable(e) => Err(StreamingError::Unreachable(e)),
90-
StreamingError::Network(e) => Err(StreamingError::Network(e)),
91-
StreamingError::RemoteError(e) => Err(StreamingError::Unreachable(Unreachable::new(&e.source))),
92-
},
93-
}
94-
}
95-
}

openraft/src/error/streaming_error.rs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use std::error::Error;
2-
3-
use crate::error::Fatal;
4-
use crate::error::Infallible;
51
use crate::error::NetworkError;
62
use crate::error::RPCError;
7-
use crate::error::RemoteError;
83
use crate::error::ReplicationClosed;
94
use crate::error::ReplicationError;
105
use crate::error::Timeout;
@@ -16,13 +11,8 @@ use crate::StorageError;
1611
///
1712
/// Thus this error includes storage error, network error, and remote error.
1813
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
19-
#[cfg_attr(
20-
feature = "serde",
21-
derive(serde::Serialize, serde::Deserialize),
22-
serde(bound(serialize = "E: serde::Serialize")),
23-
serde(bound(deserialize = "E: for <'d> serde::Deserialize<'d>"))
24-
)]
25-
pub enum StreamingError<C: RaftTypeConfig, E: Error = Infallible> {
14+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15+
pub enum StreamingError<C: RaftTypeConfig> {
2616
/// The replication stream is closed intentionally.
2717
#[error(transparent)]
2818
Closed(#[from] ReplicationClosed),
@@ -42,24 +32,16 @@ pub enum StreamingError<C: RaftTypeConfig, E: Error = Infallible> {
4232
/// Failed to send the RPC request and should retry immediately.
4333
#[error(transparent)]
4434
Network(#[from] NetworkError),
45-
46-
/// Remote node returns an error.
47-
#[error(transparent)]
48-
RemoteError(#[from] RemoteError<C, E>),
4935
}
5036

51-
impl<C: RaftTypeConfig> From<StreamingError<C, Fatal<C>>> for ReplicationError<C> {
52-
fn from(e: StreamingError<C, Fatal<C>>) -> Self {
37+
impl<C: RaftTypeConfig> From<StreamingError<C>> for ReplicationError<C> {
38+
fn from(e: StreamingError<C>) -> Self {
5339
match e {
5440
StreamingError::Closed(e) => ReplicationError::Closed(e),
5541
StreamingError::StorageError(e) => ReplicationError::StorageError(e),
5642
StreamingError::Timeout(e) => ReplicationError::RPCError(RPCError::Timeout(e)),
5743
StreamingError::Unreachable(e) => ReplicationError::RPCError(RPCError::Unreachable(e)),
5844
StreamingError::Network(e) => ReplicationError::RPCError(RPCError::Network(e)),
59-
StreamingError::RemoteError(e) => {
60-
// Fatal on remote error is considered as unreachable.
61-
ReplicationError::RPCError(RPCError::Unreachable(Unreachable::new(&e.source)))
62-
}
6345
}
6446
}
6547
}
@@ -74,22 +56,8 @@ impl<C: RaftTypeConfig> From<RPCError<C>> for StreamingError<C> {
7456
unreachable!("PayloadTooLarge should not be converted to StreamingError")
7557
}
7658
RPCError::Network(e) => StreamingError::Network(e),
77-
RPCError::RemoteError(e) => StreamingError::RemoteError(e),
78-
}
79-
}
80-
}
81-
82-
impl<C: RaftTypeConfig> From<StreamingError<C>> for ReplicationError<C> {
83-
fn from(e: StreamingError<C>) -> Self {
84-
#[allow(unreachable_patterns)]
85-
match e {
86-
StreamingError::Closed(e) => ReplicationError::Closed(e),
87-
StreamingError::StorageError(e) => ReplicationError::StorageError(e),
88-
StreamingError::Timeout(e) => ReplicationError::RPCError(RPCError::Timeout(e)),
89-
StreamingError::Unreachable(e) => ReplicationError::RPCError(RPCError::Unreachable(e)),
90-
StreamingError::Network(e) => ReplicationError::RPCError(RPCError::Network(e)),
91-
StreamingError::RemoteError(_e) => {
92-
unreachable!("Infallible error should not be converted to ReplicationError")
59+
RPCError::RemoteError(_e) => {
60+
unreachable!("Infallible error should not be produced at all")
9361
}
9462
}
9563
}

0 commit comments

Comments
 (0)