diff --git a/curp/src/client.rs b/curp/src/client.rs index e1be32a03..9b4ab0b92 100644 --- a/curp/src/client.rs +++ b/curp/src/client.rs @@ -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)); } } } diff --git a/curp/src/rpc/mod.rs b/curp/src/rpc/mod.rs index 9586c2da1..748a39f9b 100644 --- a/curp/src/rpc/mod.rs +++ b/curp/src/rpc/mod.rs @@ -176,7 +176,7 @@ impl WaitSyncedResponse { unreachable!("should not call after sync if execution fails") } (None, None) => WaitSyncedResponse::new_error(&SyncError::::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") @@ -184,15 +184,15 @@ impl WaitSyncedResponse { (Some(Err(err)), None) => { WaitSyncedResponse::new_error(&SyncError::::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::::AfterSyncError(err)) + WaitSyncedResponse::new_error(&SyncError::::ExecuteError(err)) } (Some(Ok(er)), Some(Ok(asr))) => WaitSyncedResponse::new_success::(&asr, &er), (Some(Ok(_er)), None) => { - // FIXME: should er be returned? WaitSyncedResponse::new_error(&SyncError::::AfterSyncError( - "can't get after sync result".to_owned().into(), + "can't get after sync result".to_owned(), )) // this is highly unlikely to happen, } } @@ -233,7 +233,7 @@ pub(crate) enum SyncError { /// 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