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
@@ -4,63 +4,22 @@
|
||||
use nymsphinx_acknowledgements::surb_ack::SurbAckRecoveryError;
|
||||
use nymsphinx_addressing::nodes::NymNodeRoutingAddressError;
|
||||
use nymsphinx_types::Error as SphinxError;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum MixProcessingError {
|
||||
SphinxProcessingError(SphinxError),
|
||||
InvalidHopAddress(NymNodeRoutingAddressError),
|
||||
NoSurbAckInFinalHop,
|
||||
MalformedSurbAck(SurbAckRecoveryError),
|
||||
#[error("failed to process received packet: {0}")]
|
||||
SphinxProcessingError(#[from] SphinxError),
|
||||
|
||||
#[error("the forward hop address was malformed: {0}")]
|
||||
InvalidForwardHopAddress(#[from] NymNodeRoutingAddressError),
|
||||
|
||||
#[error("the final hop did not contain a SURB-Ack")]
|
||||
NoSurbAckInFinalHop,
|
||||
|
||||
#[error("failed to recover the expected SURB-Ack packet: {0}")]
|
||||
MalformedSurbAck(#[from] SurbAckRecoveryError),
|
||||
|
||||
#[error("the received packet was set to use the very old and very much deprecated 'VPN' mode")]
|
||||
ReceivedOldTypeVpnPacket,
|
||||
}
|
||||
|
||||
impl From<SphinxError> for MixProcessingError {
|
||||
// for the time being just have a single error instance for all possible results of SphinxError
|
||||
fn from(err: SphinxError) -> Self {
|
||||
use MixProcessingError::*;
|
||||
|
||||
SphinxProcessingError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NymNodeRoutingAddressError> for MixProcessingError {
|
||||
fn from(err: NymNodeRoutingAddressError) -> Self {
|
||||
use MixProcessingError::*;
|
||||
|
||||
InvalidHopAddress(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SurbAckRecoveryError> for MixProcessingError {
|
||||
fn from(err: SurbAckRecoveryError) -> Self {
|
||||
use MixProcessingError::*;
|
||||
|
||||
MalformedSurbAck(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for MixProcessingError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
MixProcessingError::SphinxProcessingError(sphinx_err) => {
|
||||
write!(f, "Sphinx Processing Error - {}", sphinx_err)
|
||||
}
|
||||
MixProcessingError::InvalidHopAddress(address_err) => {
|
||||
write!(f, "Invalid Hop Address - {:?}", address_err)
|
||||
}
|
||||
MixProcessingError::NoSurbAckInFinalHop => {
|
||||
write!(f, "No SURBAck present in the final hop data")
|
||||
}
|
||||
MixProcessingError::MalformedSurbAck(surb_ack_err) => {
|
||||
write!(f, "Malformed SURBAck - {:?}", surb_ack_err)
|
||||
}
|
||||
MixProcessingError::ReceivedOldTypeVpnPacket => {
|
||||
write!(f, "Received an old-type unsafe 'VPN' mode packet")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for MixProcessingError {}
|
||||
|
||||
@@ -51,7 +51,7 @@ impl SphinxPacketProcessor {
|
||||
packet: SphinxPacket,
|
||||
) -> Result<ProcessedPacket, MixProcessingError> {
|
||||
packet.process(&self.sphinx_key).map_err(|err| {
|
||||
debug!("Failed to unwrap Sphinx packet: {:?}", err);
|
||||
debug!("Failed to unwrap Sphinx packet: {err}");
|
||||
MixProcessingError::SphinxProcessingError(err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -53,13 +53,13 @@ impl Display for RttError {
|
||||
write!(f, "The received reply packet had invalid signature")
|
||||
}
|
||||
RttError::UnreachableNode(id, err) => {
|
||||
write!(f, "Could not establish connection to {} - {}", id, err)
|
||||
write!(f, "Could not establish connection to {} - {err}", id)
|
||||
}
|
||||
RttError::UnexpectedConnectionFailureWrite(id, err) => {
|
||||
write!(f, "Failed to write echo packet to {} - {}", id, err)
|
||||
write!(f, "Failed to write echo packet to {} - {err}", id)
|
||||
}
|
||||
RttError::UnexpectedConnectionFailureRead(id, err) => {
|
||||
write!(f, "Failed to read reply packet from {} - {}", id, err)
|
||||
write!(f, "Failed to read reply packet from {} - {err}", id)
|
||||
}
|
||||
RttError::ConnectionReadTimeout(id) => {
|
||||
write!(f, "Timed out while trying to read reply packet from {}", id)
|
||||
|
||||
@@ -66,7 +66,7 @@ impl PacketListener {
|
||||
|
||||
tokio::spawn(connection_handler.handle_connection(socket, remote_addr, handler_shutdown_listener));
|
||||
}
|
||||
Err(err) => warn!("Failed to accept incoming connection - {:?}", err),
|
||||
Err(err) => warn!("Failed to accept incoming connection - {err}"),
|
||||
}
|
||||
},
|
||||
_ = shutdown_listener.recv() => {
|
||||
@@ -141,9 +141,9 @@ enum EchoPacketCodecError {
|
||||
impl Display for EchoPacketCodecError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
EchoPacketCodecError::IoError(err) => write!(f, "encountered io error - {}", err),
|
||||
EchoPacketCodecError::IoError(err) => write!(f, "encountered io error - {err}"),
|
||||
EchoPacketCodecError::PacketRecoveryError(err) => {
|
||||
write!(f, "failed to correctly decode an echo packet - {}", err)
|
||||
write!(f, "failed to correctly decode an echo packet - {err}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user