Skip to content

Commit

Permalink
Rename error variants
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson committed Oct 1, 2024
1 parent d746f0d commit ab64217
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,34 @@ pub enum Error {
WrongNetwork,
WrongCommand,
Serde,
Network(std::io::Error),
Cipher(bip324::Error),
Io(std::io::Error),
Protocol(bip324::Error),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::WrongNetwork => write!(f, "recieved message on wrong network"),
Error::Network(e) => write!(f, "network {}", e),
Error::Io(e) => write!(f, "network {}", e),
Error::WrongCommand => write!(f, "recieved message with wrong command"),
Error::Cipher(e) => write!(f, "cipher encryption/decrytion error {}", e),
Error::Protocol(e) => write!(f, "protocol error {}", e),
Error::Serde => write!(f, "unable to serialize command"),
}
}
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Network(e) => Some(e),
Error::WrongNetwork => None,
Error::WrongCommand => None,
Error::Cipher(e) => Some(e),
Error::Serde => None,
}
}
}
impl std::error::Error for Error {}

impl From<bip324::Error> for Error {
fn from(e: bip324::Error) -> Self {
Error::Cipher(e)
Error::Protocol(e)
}
}

// Convert IO errors.
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Network(e)
Error::Io(e)
}
}

Expand Down

0 comments on commit ab64217

Please sign in to comment.