diff options
author | Alex Auvolat <alex@adnab.me> | 2021-10-12 17:59:46 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-10-12 17:59:46 +0200 |
commit | f87dbe73dc12f2d6eb13850a3bc4b012aadd3c9b (patch) | |
tree | 5407c8eab331d066e66f5193d51f6fd66bedb9bb /src/error.rs | |
parent | 040231d554b74e981644e606c096ced6fc36a2ad (diff) | |
download | netapp-f87dbe73dc12f2d6eb13850a3bc4b012aadd3c9b.tar.gz netapp-f87dbe73dc12f2d6eb13850a3bc4b012aadd3c9b.zip |
WIP v0.3.0 with changed API
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs index 469670a..14c6187 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,13 +22,36 @@ pub enum Error { #[error(display = "Handshake error: {}", _0)] Handshake(#[error(source)] kuska_handshake::async_std::Error), + #[error(display = "UTF8 error: {}", _0)] + UTF8(#[error(source)] std::string::FromUtf8Error), + #[error(display = "{}", _0)] Message(String), + #[error(display = "No handler / shutting down")] + NoHandler, + #[error(display = "Remote error: {}", _0)] Remote(String), } +impl Error { + pub fn code(&self) -> u8 { + match self { + Self::Io(_) => 100, + Self::TokioJoin(_) => 110, + Self::OneshotRecv(_) => 111, + Self::RMPEncode(_) => 10, + Self::RMPDecode(_) => 11, + Self::UTF8(_) => 12, + Self::NoHandler => 20, + Self::Handshake(_) => 30, + Self::Remote(_) => 40, + Self::Message(_) => 99, + } + } +} + impl<T> From<tokio::sync::watch::error::SendError<T>> for Error { fn from(_e: tokio::sync::watch::error::SendError<T>) -> Error { Error::Message("Watch send error".into()) |