use std::str::Utf8Error;
use std::sync::Arc;
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 thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum Error {
#[error("connection")]
Connection,
#[error("utf8 decode: {0}")]
Utf8Decode(#[from] Utf8Error),
#[error("negotiation")]
Negotiation,
#[error("tls required")]
TlsRequired,
#[error("already connected with tls")]
AlreadyTls,
// TODO: specify unsupported feature
#[error("unsupported feature")]
Unsupported,
#[error("jid missing localpart")]
NoLocalpart,
#[error("received unexpected element: {0:?}")]
UnexpectedElement(peanuts::Element),
#[error("xml error: {0}")]
XML(#[from] peanuts::Error),
#[error("sasl error: {0}")]
SASL(#[from] SASLError),
#[error("jid error: {0}")]
JID(#[from] ParseError),
#[error("client stanza error: {0}")]
ClientError(#[from] ClientError),
#[error("stream error: {0}")]
StreamError(#[from] StreamError),
#[error("error missing")]
MissingError,
}
#[derive(Error, Debug, Clone)]
pub enum SASLError {
#[error("sasl error: {0}")]
SASL(Arc<rsasl::prelude::SASLError>),
#[error("mechanism error: {0}")]
MechanismName(#[from] MechanismNameError),
#[error("authentication failure: {0}")]
Authentication(#[from] Failure),
}
impl From<rsasl::prelude::SASLError> for SASLError {
fn from(e: rsasl::prelude::SASLError) -> Self {
Self::SASL(Arc::new(e))
}
}