From 43d2697aaa871fcb026b08c1e1908ffef34a59a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 16 Oct 2022 10:57:24 +0200 Subject: [PATCH] error: Add Error::Jid(Box) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/error.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 2af1b3a..fc0f83b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,7 +17,7 @@ use std::error::Error as StdError; use std::fmt; use tokio_xmpp::Error as TokioXMPPError; -use xmpp_parsers::{Error as ParserError, FullJid, Jid}; +use xmpp_parsers::{Error as ParserError, FullJid, Jid, JidParseError}; #[derive(Debug)] pub enum Error { @@ -31,6 +31,8 @@ pub enum Error { SessionAlreadyExists(FullJid), /// Raised when fetching an occupant with a nickname that isn't assigned in the room. ParticipantNotFound(String), + /// Jid Parse errors + Jid(Box), /// TokioXMPP errors Xmpp(Box), /// Parser errors @@ -47,12 +49,19 @@ impl fmt::Display for Error { Error::NonexistantSession(err) => write!(f, "Session doesn't exist: {}", err), Error::SessionAlreadyExists(err) => write!(f, "Session already exist: {}", err), Error::ParticipantNotFound(err) => write!(f, "Participant not found: {}", err), + Error::Jid(err) => write!(f, "Jid Parse error: {}", err), Error::Xmpp(err) => write!(f, "XMPP error: {}", err), Error::Parser(err) => write!(f, "Parser error: {}", err), } } } +impl From for Error { + fn from(err: JidParseError) -> Error { + Error::Jid(Box::new(err)) + } +} + impl From for Error { fn from(err: TokioXMPPError) -> Error { Error::Xmpp(Box::new(err))