-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sdk): consensus error 2 #2275
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
//! Definitions of errors | ||
|
||
use std::any::Any; | ||
use std::fmt::Debug; | ||
use std::time::Duration; | ||
|
||
use dapi_grpc::mock::Mockable; | ||
use dpp::consensus::ConsensusError; | ||
use dpp::serialization::PlatformDeserializable; | ||
use dpp::version::PlatformVersionError; | ||
use dpp::ProtocolError; | ||
use rs_dapi_client::{CanRetry, DapiClientError}; | ||
|
@@ -73,8 +77,24 @@ pub enum Error { | |
StaleNode(#[from] StaleNodeError), | ||
} | ||
|
||
impl<T: Debug + Mockable> From<DapiClientError<T>> for Error { | ||
impl<T: Debug + Mockable + Any> From<DapiClientError<T>> for Error { | ||
fn from(value: DapiClientError<T>) -> Self { | ||
if let DapiClientError::Transport(ref t, _) = &value { | ||
if let Some(status) = (t as &dyn Any).downcast_ref::<dapi_grpc::tonic::Status>() { | ||
if let Some(consensus_error_value) = | ||
status.metadata().get_bin("drive-error-data-bin") | ||
{ | ||
return ConsensusError::deserialize_from_bytes( | ||
consensus_error_value.as_encoded_bytes(), | ||
) | ||
.map(|consensus_error| { | ||
Error::Protocol(ProtocolError::ConsensusError(Box::new(consensus_error))) | ||
}) | ||
.unwrap_or_else(Error::Protocol); | ||
} | ||
Comment on lines
+87
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider enhancing error handling granularity The current implementation silently falls back to a generic Protocol error if deserialization fails. Consider providing more specific error information in failure cases. - return ConsensusError::deserialize_from_bytes(
- consensus_error_value.as_encoded_bytes(),
- )
- .map(|consensus_error| {
- Error::Protocol(ProtocolError::ConsensusError(Box::new(consensus_error)))
- })
- .unwrap_or_else(Error::Protocol);
+ return match ConsensusError::deserialize_from_bytes(
+ consensus_error_value.as_encoded_bytes(),
+ ) {
+ Ok(consensus_error) => {
+ Error::Protocol(ProtocolError::ConsensusError(Box::new(consensus_error)))
+ }
+ Err(e) => Error::Protocol(ProtocolError::Generic(format!(
+ "Failed to deserialize consensus error: {}",
+ e
+ ))),
+ };
|
||
} | ||
} | ||
|
||
Self::DapiClientError(format!("{:?}", value)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently cbor is inside. We should do it without cbor