Chore/more error macros (#2686)
* cleaned up MixProcessingError
* Added Error impl to (hopefully) all error enums in the codebase
* Replaced all occurences of error("{0}") with error(transparent)
* Changelog entry
This commit is contained in:
committed by
GitHub
parent
a020f2ad1c
commit
97b01db23e
@@ -182,7 +182,7 @@ where
|
||||
/// * `mix_packet`: packet received from the client that should get forwarded into the network.
|
||||
fn forward_packet(&self, mix_packet: MixPacket) {
|
||||
if let Err(err) = self.inner.outbound_mix_sender.unbounded_send(mix_packet) {
|
||||
error!("We failed to forward requested mix packet - {}. Presumably our mix forwarder has crashed. We cannot continue.", err);
|
||||
error!("We failed to forward requested mix packet - {err}. Presumably our mix forwarder has crashed. We cannot continue.");
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -426,7 +426,7 @@ where
|
||||
None => break,
|
||||
Some(Ok(socket_msg)) => socket_msg,
|
||||
Some(Err(err)) => {
|
||||
error!("failed to obtain message from websocket stream! stopping connection handler: {}", err);
|
||||
error!("failed to obtain message from websocket stream! stopping connection handler: {err}");
|
||||
break;
|
||||
}
|
||||
};
|
||||
@@ -438,8 +438,7 @@ where
|
||||
if let Some(response) = self.handle_request(socket_msg).await {
|
||||
if let Err(err) = self.inner.send_websocket_message(response).await {
|
||||
warn!(
|
||||
"Failed to send message over websocket: {}. Assuming the connection is dead.",
|
||||
err
|
||||
"Failed to send message over websocket: {err}. Assuming the connection is dead.",
|
||||
);
|
||||
break;
|
||||
}
|
||||
@@ -447,8 +446,8 @@ where
|
||||
},
|
||||
mix_messages = self.mix_receiver.next() => {
|
||||
let mix_messages = mix_messages.expect("sender was unexpectedly closed! this shouldn't have ever happened!");
|
||||
if let Err(e) = self.inner.push_packets_to_client(self.client.shared_keys, mix_messages).await {
|
||||
warn!("failed to send the unwrapped sphinx packets back to the client - {:?}, assuming the connection is dead", e);
|
||||
if let Err(err) = self.inner.push_packets_to_client(self.client.shared_keys, mix_messages).await {
|
||||
warn!("failed to send the unwrapped sphinx packets back to the client - {err}, assuming the connection is dead");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,7 +586,7 @@ where
|
||||
let msg = match msg {
|
||||
Ok(msg) => msg,
|
||||
Err(err) => {
|
||||
error!("failed to obtain message from websocket stream! stopping connection handler: {}", err);
|
||||
error!("failed to obtain message from websocket stream! stopping connection handler: {err}");
|
||||
break;
|
||||
}
|
||||
};
|
||||
@@ -605,7 +605,7 @@ where
|
||||
if let Err(err) =
|
||||
self.send_websocket_message(err.into_error_message()).await
|
||||
{
|
||||
debug!("Failed to send authentication error response - {}", err);
|
||||
debug!("Failed to send authentication error response - {err}");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
@@ -614,7 +614,7 @@ where
|
||||
.send_websocket_message(auth_result.server_response.into())
|
||||
.await
|
||||
{
|
||||
debug!("Failed to send authentication response - {}", err);
|
||||
debug!("Failed to send authentication response - {err}");
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Listener {
|
||||
let tcp_listener = match tokio::net::TcpListener::bind(self.address).await {
|
||||
Ok(listener) => listener,
|
||||
Err(err) => {
|
||||
error!("Failed to bind the websocket to {} - {}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address, err);
|
||||
error!("Failed to bind the websocket to {} - {err}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
@@ -79,7 +79,7 @@ impl Listener {
|
||||
);
|
||||
tokio::spawn(async move { handle.start_handling().await });
|
||||
}
|
||||
Err(e) => warn!("failed to get client: {:?}", e),
|
||||
Err(err) => warn!("failed to get client: {err}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ impl<St: Storage> ConnectionHandler<St> {
|
||||
.store_processed_packet_payload(client_address, unsent_plaintext)
|
||||
.await
|
||||
{
|
||||
Err(err) => error!("Failed to store client data - {}", err),
|
||||
Err(err) => error!("Failed to store client data - {err}"),
|
||||
Ok(_) => trace!("Stored packet for {}", client_address),
|
||||
},
|
||||
Ok(_) => trace!("Pushed received packet to {}", client_address),
|
||||
@@ -163,8 +163,8 @@ impl<St: Storage> ConnectionHandler<St> {
|
||||
|
||||
let processed_final_hop = match self.packet_processor.process_received(framed_sphinx_packet)
|
||||
{
|
||||
Err(e) => {
|
||||
debug!("We failed to process received sphinx packet - {:?}", e);
|
||||
Err(err) => {
|
||||
debug!("We failed to process received sphinx packet - {err}");
|
||||
return;
|
||||
}
|
||||
Ok(processed_final_hop) => processed_final_hop,
|
||||
|
||||
@@ -26,7 +26,7 @@ impl Listener {
|
||||
let tcp_listener = match tokio::net::TcpListener::bind(self.address).await {
|
||||
Ok(listener) => listener,
|
||||
Err(err) => {
|
||||
error!("Failed to bind to {} - {}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address, err);
|
||||
error!("Failed to bind to {} - {err}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
@@ -37,7 +37,7 @@ impl Listener {
|
||||
let handler = connection_handler.clone();
|
||||
tokio::spawn(handler.handle_connection(socket, remote_addr));
|
||||
}
|
||||
Err(e) => warn!("failed to get client: {:?}", e),
|
||||
Err(err) => warn!("failed to get client: {err}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,17 @@ use mixnode_common::packet_processor::error::MixProcessingError;
|
||||
pub use mixnode_common::packet_processor::processor::MixProcessingResult;
|
||||
use mixnode_common::packet_processor::processor::{ProcessedFinalHop, SphinxPacketProcessor};
|
||||
use nymsphinx::framing::packet::FramedSphinxPacket;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum GatewayProcessingError {
|
||||
PacketProcessingError(MixProcessingError),
|
||||
#[error("failed to process received mix packet - {0}")]
|
||||
PacketProcessingError(#[from] MixProcessingError),
|
||||
|
||||
#[error("received a forward hop mix packet")]
|
||||
ForwardHopReceivedError,
|
||||
}
|
||||
|
||||
impl From<MixProcessingError> for GatewayProcessingError {
|
||||
fn from(e: MixProcessingError) -> Self {
|
||||
use GatewayProcessingError::*;
|
||||
|
||||
PacketProcessingError(e)
|
||||
}
|
||||
}
|
||||
|
||||
// PacketProcessor contains all data required to correctly unwrap and store sphinx packets
|
||||
#[derive(Clone)]
|
||||
pub struct PacketProcessor {
|
||||
|
||||
@@ -46,7 +46,7 @@ async fn initialise_storage(config: &Config) -> PersistentStorage {
|
||||
let path = config.get_persistent_store_path();
|
||||
let retrieval_limit = config.get_message_retrieval_limit();
|
||||
match PersistentStorage::init(path, retrieval_limit).await {
|
||||
Err(err) => panic!("failed to initialise gateway storage - {}", err),
|
||||
Err(err) => panic!("failed to initialise gateway storage - {err}"),
|
||||
Ok(storage) => storage,
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ where
|
||||
let existing_gateways = match validator_client.get_cached_gateways().await {
|
||||
Ok(gateways) => gateways,
|
||||
Err(err) => {
|
||||
error!("failed to grab initial network gateways - {}\n Please try to startup again in few minutes", err);
|
||||
error!("failed to grab initial network gateways - {err}\n Please try to startup again in few minutes");
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,13 +173,13 @@ impl PersistentStorage {
|
||||
let connection_pool = match sqlx::SqlitePool::connect_with(opts).await {
|
||||
Ok(db) => db,
|
||||
Err(err) => {
|
||||
error!("Failed to connect to SQLx database: {}", err);
|
||||
error!("Failed to connect to SQLx database: {err}");
|
||||
return Err(err.into());
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(err) = sqlx::migrate!("./migrations").run(&connection_pool).await {
|
||||
error!("Failed to perform migration on the SQLx database: {}", err);
|
||||
error!("Failed to perform migration on the SQLx database: {err}");
|
||||
return Err(err.into());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user