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 2, 2024
1 parent 66f4f46 commit 2a9e6b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
5 changes: 1 addition & 4 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ impl std::error::Error for ProtocolError {}
impl fmt::Display for ProtocolError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ProtocolError::Io(e) => write!(f, "IO error: {}", e),
ProtocolError::Io(e) => write!(f, "IO error: {:?}", e),
ProtocolError::Internal(e) => write!(f, "Internal error: {:?}", e),
}
}
Expand Down Expand Up @@ -1169,9 +1169,6 @@ where

#[cfg(test)]
mod tests {
//! Any tests requiring a random number generator are currently
//! gated with the std feature flag.
use super::*;
use core::str::FromStr;
use hex::prelude::*;
Expand Down
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 2a9e6b2

Please sign in to comment.