diff options
author | Alex Auvolat <alex@adnab.me> | 2021-10-13 17:12:13 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-10-13 17:12:13 +0200 |
commit | 70839d70d86354232f168e63ce4062219acb85c7 (patch) | |
tree | 9c956af0339aa048f487c3a4e54c320be8d13647 /src/error.rs | |
parent | 8dede69dee20b812ad1dcab5b374c60232409f4f (diff) | |
download | netapp-70839d70d86354232f168e63ce4062219acb85c7.tar.gz netapp-70839d70d86354232f168e63ce4062219acb85c7.zip |
Try to handle termination and closing of stuff properly
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs index 14c6187..0ed30a5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -31,6 +31,9 @@ pub enum Error { #[error(display = "No handler / shutting down")] NoHandler, + #[error(display = "Connection closed")] + ConnectionClosed, + #[error(display = "Remote error: {}", _0)] Remote(String), } @@ -45,6 +48,7 @@ impl Error { Self::RMPDecode(_) => 11, Self::UTF8(_) => 12, Self::NoHandler => 20, + Self::ConnectionClosed => 21, Self::Handshake(_) => 30, Self::Remote(_) => 40, Self::Message(_) => 99, @@ -80,3 +84,16 @@ where }; } } + +impl<E, T> LogError for Result<T, E> +where + T: LogError, + E: Into<Error>, +{ + fn log_err(self, msg: &'static str) { + match self { + Err(e) => error!("Error: {}: {}", msg, Into::<Error>::into(e)), + Ok(x) => x.log_err(msg), + } + } +} |