Pass errors up the call stack
This commit is contained in:
@@ -85,18 +85,21 @@ impl MixTrafficController {
|
||||
error!("Failed to send sphinx packet(s) to the gateway: {err}");
|
||||
self.consecutive_gateway_failure_count += 1;
|
||||
if self.consecutive_gateway_failure_count == MAX_FAILURE_COUNT {
|
||||
// todo: in the future this should initiate a 'graceful' shutdown or try
|
||||
// to reconnect?
|
||||
panic!("failed to send sphinx packet to the gateway {MAX_FAILURE_COUNT} times in a row - assuming the gateway is dead. Can't do anything about it yet :(")
|
||||
Err(ClientCoreError::GatewayMaxRetriesExceeded)
|
||||
} else {
|
||||
Err(ClientCoreError::GatewayClientSendError {
|
||||
gateway_client_error: err.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
Ok(_) => {
|
||||
trace!("We *might* have managed to forward sphinx packet(s) to the gateway!");
|
||||
self.consecutive_gateway_failure_count = 0;
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
info!("JON: MixTrafficController: done sending sphinx packets to the gateway");
|
||||
Ok(r)
|
||||
r
|
||||
}
|
||||
|
||||
pub fn start_with_shutdown(mut self, mut shutdown: nym_task::TaskClient) {
|
||||
@@ -120,10 +123,6 @@ impl MixTrafficController {
|
||||
if let Err(err) = self.on_messages(mix_packets).await {
|
||||
log::error!("MixTrafficController: failed to send mix packets to the gateway: {err}");
|
||||
}
|
||||
// let r = tokio::time::timeout(tokio::time::Duration::from_secs(4), self.on_messages(mix_packets)).await;
|
||||
// if r.is_err() {
|
||||
// error!("MixTrafficController: Failed to send mix packets to the gateway");
|
||||
// }
|
||||
log::info!("JON: MixTrafficController: done with mix_rx recv");
|
||||
},
|
||||
None => {
|
||||
|
||||
@@ -19,6 +19,12 @@ use futures::channel::{mpsc, oneshot};
|
||||
#[error(transparent)]
|
||||
pub struct ErasedGatewayError(Box<dyn std::error::Error + Send + Sync>);
|
||||
|
||||
impl ErasedGatewayError {
|
||||
pub fn downcast<T: std::error::Error + 'static>(&self) -> Option<&T> {
|
||||
self.0.downcast_ref::<T>()
|
||||
}
|
||||
}
|
||||
|
||||
fn erase_err<E: std::error::Error + Send + Sync + 'static>(err: E) -> ErasedGatewayError {
|
||||
ErasedGatewayError(Box::new(err))
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ pub enum ClientCoreError {
|
||||
source: tungstenite::Error,
|
||||
},
|
||||
|
||||
#[error("max number of retries for gateway connection has been exceeded")]
|
||||
GatewayMaxRetriesExceeded,
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[error("failed to establish gateway connection (wasm)")]
|
||||
GatewayJsConnectionFailure,
|
||||
@@ -88,6 +91,11 @@ pub enum ClientCoreError {
|
||||
#[error("timed out while trying to establish gateway connection")]
|
||||
GatewayConnectionTimeout,
|
||||
|
||||
#[error("failed to send sphinx packet to the gateway: {gateway_client_error}")]
|
||||
GatewayClientSendError {
|
||||
gateway_client_error: String,
|
||||
},
|
||||
|
||||
#[error("no ping measurements for the gateway ({identity}) performed")]
|
||||
NoGatewayMeasurements { identity: String },
|
||||
|
||||
|
||||
@@ -74,6 +74,9 @@ pub enum GatewayClientError {
|
||||
#[error("Timed out")]
|
||||
Timeout,
|
||||
|
||||
#[error("timeout sending ws message to the gateway")]
|
||||
TimeoutOnSendingWs,
|
||||
|
||||
#[error("Failed to send mixnet message")]
|
||||
MixnetMsgSenderFailedToSend,
|
||||
|
||||
|
||||
@@ -222,14 +222,14 @@ impl PartiallyDelegated {
|
||||
// Ok(r?)
|
||||
let r = tokio::time::timeout(Duration::from_secs(3), self.sink_half.send(msg)).await;
|
||||
let rr = match r {
|
||||
Ok(rr) => rr,
|
||||
Ok(rr) => Ok(rr?),
|
||||
Err(_) => {
|
||||
log::error!("JON: PartiallyDelegated::send_without_response - timeout sending a message");
|
||||
Ok(())
|
||||
Err(GatewayClientError::TimeoutOnSendingWs)
|
||||
}
|
||||
};
|
||||
log::info!("JON: PartiallyDelegated::send_without_response - sent a message: {rr:?}");
|
||||
Ok(rr?)
|
||||
rr
|
||||
}
|
||||
|
||||
pub(crate) async fn batch_send_without_response(
|
||||
|
||||
Reference in New Issue
Block a user