luz/jabber/src/error.rs

88 lines
1.8 KiB
Rust

use std::str::Utf8Error;
use jid::ParseError;
use rsasl::mechname::MechanismNameError;
use stanza::client::error::Error as ClientError;
use stanza::sasl::Failure;
use stanza::stream::Error as StreamError;
use tokio::task::JoinError;
#[derive(Debug)]
pub enum Error {
Connection,
Utf8Decode,
Negotiation,
TlsRequired,
AlreadyTls,
Unsupported,
NoLocalpart,
AlreadyConnecting,
StreamClosed,
UnexpectedElement(peanuts::Element),
XML(peanuts::Error),
Deserialization(peanuts::DeserializeError),
SASL(SASLError),
JID(ParseError),
Authentication(Failure),
ClientError(ClientError),
StreamError(StreamError),
MissingError,
Disconnected,
Connecting,
JoinError(JoinError),
}
#[derive(Debug)]
pub enum SASLError {
SASL(rsasl::prelude::SASLError),
MechanismName(MechanismNameError),
}
impl From<rsasl::prelude::SASLError> for Error {
fn from(e: rsasl::prelude::SASLError) -> Self {
Self::SASL(SASLError::SASL(e))
}
}
impl From<JoinError> for Error {
fn from(e: JoinError) -> Self {
Self::JoinError(e)
}
}
impl From<peanuts::DeserializeError> for Error {
fn from(e: peanuts::DeserializeError) -> Self {
Error::Deserialization(e)
}
}
impl From<MechanismNameError> for Error {
fn from(e: MechanismNameError) -> Self {
Self::SASL(SASLError::MechanismName(e))
}
}
impl From<SASLError> for Error {
fn from(e: SASLError) -> Self {
Self::SASL(e)
}
}
impl From<Utf8Error> for Error {
fn from(_e: Utf8Error) -> Self {
Self::Utf8Decode
}
}
impl From<peanuts::Error> for Error {
fn from(e: peanuts::Error) -> Self {
Self::XML(e)
}
}
impl From<ParseError> for Error {
fn from(e: ParseError) -> Self {
Self::JID(e)
}
}