Skip to content

Commit

Permalink
refactor: return some after sync error as execution error
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com>
  • Loading branch information
bsbds committed Jul 26, 2023
1 parent 4dd9d2a commit 5744b56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions curp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,16 @@ where
SyncResult::Error(SyncError::Timeout) => {
return Err(ProposeError::SyncedError("wait sync timeout".to_owned()));
}
SyncResult::Error(e) => {
return Err(ProposeError::SyncedError(format!("{e:?}")));
SyncResult::Error(SyncError::NoSuchCmd(id)) => {
return Err(ProposeError::SyncedError(format!(
"No such cmd to be waited, propose id: {id}"
)));
}
SyncResult::Error(SyncError::AfterSyncError(e)) => {
return Err(ProposeError::SyncedError(e));
}
SyncResult::Error(SyncError::ExecuteError(e)) => {
return Err(ProposeError::ExecutionError(e));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions curp/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,23 @@ impl WaitSyncedResponse {
unreachable!("should not call after sync if execution fails")
}
(None, None) => WaitSyncedResponse::new_error(&SyncError::<C>::AfterSyncError(
"can't get er result".to_owned().into(),
"can't get er result".to_owned(),
)), // this is highly unlikely to happen,
(Some(Err(_)), Some(_)) => {
unreachable!("should not call after_sync when exe failed")
}
(Some(Err(err)), None) => {
WaitSyncedResponse::new_error(&SyncError::<C>::ExecuteError(err))
}
// Because after sync result actually wraps the execution error, we return it as `ExecuteError`.
// There's no need to return the execution result as the execution failed anyway.
(Some(Ok(_er)), Some(Err(err))) => {
// FIXME: should er be returned?
WaitSyncedResponse::new_error(&SyncError::<C>::AfterSyncError(err))
WaitSyncedResponse::new_error(&SyncError::<C>::ExecuteError(err))
}
(Some(Ok(er)), Some(Ok(asr))) => WaitSyncedResponse::new_success::<C>(&asr, &er),
(Some(Ok(_er)), None) => {
// FIXME: should er be returned?
WaitSyncedResponse::new_error(&SyncError::<C>::AfterSyncError(
"can't get after sync result".to_owned().into(),
"can't get after sync result".to_owned(),
)) // this is highly unlikely to happen,
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ pub(crate) enum SyncError<C: Command> {
/// If the execution of the cmd went wrong
ExecuteError(C::Error),
/// If after sync of the cmd went wrong
AfterSyncError(C::Error),
AfterSyncError(String),
/// If there is no such cmd to be waited
NoSuchCmd(ProposeId),
/// Wait timeout
Expand Down

0 comments on commit 5744b56

Please sign in to comment.