aboutsummaryrefslogtreecommitdiff
path: root/karyons_p2p/src/error.rs
diff options
context:
space:
mode:
authorhozan23 <hozan23@proton.me>2023-11-08 13:03:27 +0300
committerhozan23 <hozan23@proton.me>2023-11-08 13:03:27 +0300
commit4fe665fc8bc6265baf5bfba6b6a5f3ee2dba63dc (patch)
tree77c7c40c9725539546e53b00f424deafe5ec81a8 /karyons_p2p/src/error.rs
first commit
Diffstat (limited to 'karyons_p2p/src/error.rs')
-rw-r--r--karyons_p2p/src/error.rs82
1 files changed, 82 insertions, 0 deletions
diff --git a/karyons_p2p/src/error.rs b/karyons_p2p/src/error.rs
new file mode 100644
index 0000000..945e90a
--- /dev/null
+++ b/karyons_p2p/src/error.rs
@@ -0,0 +1,82 @@
+use thiserror::Error as ThisError;
+
+pub type Result<T> = std::result::Result<T, Error>;
+
+/// Represents Karyons's p2p Error.
+#[derive(ThisError, Debug)]
+pub enum Error {
+ #[error("IO Error: {0}")]
+ IO(#[from] std::io::Error),
+
+ #[error("Unsupported protocol error: {0}")]
+ UnsupportedProtocol(String),
+
+ #[error("Invalid message error: {0}")]
+ InvalidMsg(String),
+
+ #[error("Parse error: {0}")]
+ ParseError(String),
+
+ #[error("Incompatible version error: {0}")]
+ IncompatibleVersion(String),
+
+ #[error("Config error: {0}")]
+ Config(String),
+
+ #[error("Peer shutdown")]
+ PeerShutdown,
+
+ #[error("Invalid Pong Msg")]
+ InvalidPongMsg,
+
+ #[error("Discovery error: {0}")]
+ Discovery(&'static str),
+
+ #[error("Lookup error: {0}")]
+ Lookup(&'static str),
+
+ #[error("Peer already connected")]
+ PeerAlreadyConnected,
+
+ #[error("Channel Send Error: {0}")]
+ ChannelSend(String),
+
+ #[error("Channel Receive Error: {0}")]
+ ChannelRecv(String),
+
+ #[error("CORE::ERROR : {0}")]
+ KaryonsCore(#[from] karyons_core::error::Error),
+
+ #[error("NET::ERROR : {0}")]
+ KaryonsNet(#[from] karyons_net::NetError),
+}
+
+impl<T> From<smol::channel::SendError<T>> for Error {
+ fn from(error: smol::channel::SendError<T>) -> Self {
+ 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())
+ }
+}