diff options
-rw-r--r-- | core/src/error.rs | 32 | ||||
-rw-r--r-- | net/src/error.rs | 14 | ||||
-rw-r--r-- | p2p/src/error.rs | 45 |
3 files changed, 26 insertions, 65 deletions
diff --git a/core/src/error.rs b/core/src/error.rs index 15947c8..63b45d3 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -4,7 +4,7 @@ pub type Result<T> = std::result::Result<T, Error>; #[derive(ThisError, Debug)] pub enum Error { - #[error("IO Error: {0}")] + #[error(transparent)] IO(#[from] std::io::Error), #[error("Timeout Error")] @@ -16,14 +16,14 @@ pub enum Error { #[error("Channel Send Error: {0}")] ChannelSend(String), - #[error("Channel Receive Error: {0}")] - ChannelRecv(String), + #[error(transparent)] + ChannelRecv(#[from] smol::channel::RecvError), - #[error("Decode Error: {0}")] - Decode(String), + #[error(transparent)] + BincodeDecode(#[from] bincode::error::DecodeError), - #[error("Encode Error: {0}")] - Encode(String), + #[error(transparent)] + BincodeEncode(#[from] bincode::error::EncodeError), } impl<T> From<smol::channel::SendError<T>> for Error { @@ -31,21 +31,3 @@ impl<T> From<smol::channel::SendError<T>> for Error { Error::ChannelSend(error.to_string()) } } - -impl From<smol::channel::RecvError> for Error { - fn from(error: smol::channel::RecvError) -> Self { - Error::ChannelRecv(error.to_string()) - } -} - -impl From<bincode::error::DecodeError> for Error { - fn from(error: bincode::error::DecodeError) -> Self { - Error::Decode(error.to_string()) - } -} - -impl From<bincode::error::EncodeError> for Error { - fn from(error: bincode::error::EncodeError) -> Self { - Error::Encode(error.to_string()) - } -} diff --git a/net/src/error.rs b/net/src/error.rs index a1c85db..346184a 100644 --- a/net/src/error.rs +++ b/net/src/error.rs @@ -4,7 +4,7 @@ pub type Result<T> = std::result::Result<T, Error>; #[derive(ThisError, Debug)] pub enum Error { - #[error("IO Error: {0}")] + #[error(transparent)] IO(#[from] std::io::Error), #[error("Try from endpoint Error")] @@ -25,10 +25,10 @@ pub enum Error { #[error("Channel Send Error: {0}")] ChannelSend(String), - #[error("Channel Receive Error: {0}")] - ChannelRecv(String), + #[error(transparent)] + ChannelRecv(#[from] smol::channel::RecvError), - #[error("Karyons core error : {0}")] + #[error(transparent)] KaryonsCore(#[from] karyons_core::error::Error), } @@ -37,9 +37,3 @@ impl<T> From<smol::channel::SendError<T>> for Error { Error::ChannelSend(error.to_string()) } } - -impl From<smol::channel::RecvError> for Error { - fn from(error: smol::channel::RecvError) -> Self { - Error::ChannelRecv(error.to_string()) - } -} diff --git a/p2p/src/error.rs b/p2p/src/error.rs index 91d2c39..5a62676 100644 --- a/p2p/src/error.rs +++ b/p2p/src/error.rs @@ -5,7 +5,7 @@ pub type Result<T> = std::result::Result<T, Error>; /// Represents karyons's p2p Error. #[derive(ThisError, Debug)] pub enum Error { - #[error("IO Error: {0}")] + #[error(transparent)] IO(#[from] std::io::Error), #[error("Unsupported protocol error: {0}")] @@ -14,7 +14,16 @@ pub enum Error { #[error("Invalid message error: {0}")] InvalidMsg(String), - #[error("Parse error: {0}")] + #[error(transparent)] + ParseIntError(#[from] std::num::ParseIntError), + + #[error(transparent)] + ParseFloatError(#[from] std::num::ParseFloatError), + + #[error(transparent)] + SemverError(#[from] semver::Error), + + #[error("Parse Error: {0}")] ParseError(String), #[error("Incompatible version error: {0}")] @@ -41,13 +50,13 @@ pub enum Error { #[error("Channel Send Error: {0}")] ChannelSend(String), - #[error("Channel Receive Error: {0}")] - ChannelRecv(String), + #[error(transparent)] + ChannelRecv(#[from] smol::channel::RecvError), - #[error("CORE::ERROR : {0}")] + #[error(transparent)] KaryonsCore(#[from] karyons_core::error::Error), - #[error("NET::ERROR : {0}")] + #[error(transparent)] KaryonsNet(#[from] karyons_net::NetError), } @@ -56,27 +65,3 @@ impl<T> From<smol::channel::SendError<T>> for Error { Error::ChannelSend(error.to_string()) } } - -impl From<smol::channel::RecvError> for Error { - fn from(error: smol::channel::RecvError) -> Self { - Error::ChannelRecv(error.to_string()) - } -} - -impl From<std::num::ParseIntError> for Error { - fn from(error: std::num::ParseIntError) -> Self { - Error::ParseError(error.to_string()) - } -} - -impl From<std::num::ParseFloatError> for Error { - fn from(error: std::num::ParseFloatError) -> Self { - Error::ParseError(error.to_string()) - } -} - -impl From<semver::Error> for Error { - fn from(error: semver::Error) -> Self { - Error::ParseError(error.to_string()) - } -} |