-
Notifications
You must be signed in to change notification settings - Fork 44
feat(sdk)!: return consensus errors from broadcast methods #2274
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
Changes from all commits
b24c6ca
dd785cc
7bdda0f
d84a145
3ca8abe
e19902c
65f34ce
19e6e3e
75eb334
f806087
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 |
---|---|---|
|
@@ -11,19 +11,23 @@ use tracing::Instrument; | |
|
||
use crate::address_list::AddressListError; | ||
use crate::connection_pool::ConnectionPool; | ||
use crate::transport::TransportError; | ||
use crate::{ | ||
transport::{TransportClient, TransportRequest}, | ||
Address, AddressList, CanRetry, DapiRequestExecutor, ExecutionError, ExecutionResponse, | ||
ExecutionResult, RequestSettings, | ||
AddressList, CanRetry, DapiRequestExecutor, ExecutionError, ExecutionResponse, ExecutionResult, | ||
RequestSettings, | ||
}; | ||
|
||
/// General DAPI request error type. | ||
#[derive(Debug, thiserror::Error)] | ||
#[cfg_attr(feature = "mocks", derive(serde::Serialize, serde::Deserialize))] | ||
pub enum DapiClientError<TE: Mockable> { | ||
pub enum DapiClientError { | ||
/// The error happened on transport layer | ||
#[error("transport error: {0}")] | ||
Transport(#[cfg_attr(feature = "mocks", serde(with = "dapi_grpc::mock::serde_mockable"))] TE), | ||
Transport( | ||
#[cfg_attr(feature = "mocks", serde(with = "dapi_grpc::mock::serde_mockable"))] | ||
TransportError, | ||
), | ||
/// There are no valid DAPI addresses to use. | ||
#[error("no available addresses to use")] | ||
NoAvailableAddresses, | ||
|
@@ -37,7 +41,7 @@ pub enum DapiClientError<TE: Mockable> { | |
Mock(#[from] crate::mock::MockError), | ||
} | ||
|
||
impl<TE: CanRetry + Mockable> CanRetry for DapiClientError<TE> { | ||
impl CanRetry for DapiClientError { | ||
fn can_retry(&self) -> bool { | ||
use DapiClientError::*; | ||
match self { | ||
|
@@ -50,17 +54,10 @@ impl<TE: CanRetry + Mockable> CanRetry for DapiClientError<TE> { | |
} | ||
} | ||
|
||
#[cfg(feature = "mocks")] | ||
#[derive(serde::Serialize, serde::Deserialize)] | ||
struct TransportErrorData { | ||
transport_error: Vec<u8>, | ||
address: Address, | ||
} | ||
|
||
/// Serialization of [DapiClientError]. | ||
/// | ||
/// We need to do manual serialization because of the generic type parameter which doesn't support serde derive. | ||
impl<TE: Mockable> Mockable for DapiClientError<TE> { | ||
impl Mockable for DapiClientError { | ||
#[cfg(feature = "mocks")] | ||
fn mock_serialize(&self) -> Option<Vec<u8>> { | ||
Some(serde_json::to_vec(self).expect("serialize DAPI client error")) | ||
|
@@ -110,11 +107,11 @@ impl DapiRequestExecutor for DapiClient { | |
&self, | ||
request: R, | ||
settings: RequestSettings, | ||
) -> ExecutionResult<R::Response, DapiClientError<<R::Client as TransportClient>::Error>> | ||
) -> ExecutionResult<R::Response, DapiClientError> | ||
where | ||
R: TransportRequest + Mockable, | ||
R::Response: Mockable, | ||
<R::Client as TransportClient>::Error: Mockable, | ||
TransportError: Mockable, | ||
{ | ||
// Join settings of different sources to get final version of the settings for this execution: | ||
let applied_settings = self | ||
|
@@ -148,9 +145,10 @@ impl DapiRequestExecutor for DapiClient { | |
.read() | ||
.expect("can't get address list for read"); | ||
|
||
let address_result = address_list.get_live_address().cloned().ok_or( | ||
DapiClientError::<<R::Client as TransportClient>::Error>::NoAvailableAddresses, | ||
); | ||
let address_result = address_list | ||
.get_live_address() | ||
.cloned() | ||
.ok_or(DapiClientError::NoAvailableAddresses); | ||
Comment on lines
+148
to
+151
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. Handle The change at lines 148-151 introduces Consider adding user-friendly messages or logging to help diagnose issues when no addresses are available, enhancing the developer experience during debugging. |
||
|
||
drop(address_list); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.