Replies: 2 comments 3 replies
-
+1 for making error types configurable, probably via @xDarksome The error you mentioned would then probably have a trait bound We learned the hard way in our project that error handling requires a bit more careful design - we have currently too many error enums, also deeply nested, and their value is practically zero. But they take many resources unnecessarily (especially making return types large). Therefore, I would suggest to collect some proposals for a holistic approach and only decide on the best one afterwards. |
Beta Was this translation helpful? Give feedback.
-
Thank you two guys for your well-thought-out suggestion on enhancing network error management. We can refactor network error handling in the following manner:
Regarding other errors currently in use:
Building upon your proposal for the new trait RaftNetworkError: std::error::Error {
fn is_permanent_error() -> bool;
}
pub trait RaftNetwork<C>: Send + Sync + 'static
where C: RaftTypeConfig
{
type Err: RaftNetworkError; // maybe some trait bounds here
// The following are same as your proposed:
async fn send_append_entries(
&mut self,
rpc: AppendEntriesRequest<C>,
) -> Result<AppendEntriesResponse<C::NodeId>, Self::Err>;
async fn send_install_snapshot(
&mut self,
rpc: InstallSnapshotRequest<C>,
) -> Result<
InstallSnapshotResponse<C::NodeId>,
RPCError<C::NodeId, C::Node, Self::Err>,
>;
async fn send_vote(
&mut self,
rpc: VoteRequest<C::NodeId>,
) -> Result<VoteResponse<C::NodeId>, Self::Err>;
} |
Beta Was this translation helpful? Give feedback.
-
The current
RaftNetwork
interface requires to serialize/deserialize these error variants (listed them as a single enum for simplicity):This forces the driver network API adapter (besides the driven adapter) to also return these types. Although our application only cares about the following:
I looked through the
openraft
codebase and it seems to me that those errors currently aren't required at all for RPC error handling. All of them are just being converted intoString
for summary / logging.It looks like the code that calls
RaftNetwork
functions is only concerned about whether there is an error and not the specifics of the error.Does it make sense / is it possible to have the following
RaftNetwork
API?Beta Was this translation helpful? Give feedback.
All reactions