aboutsummaryrefslogblamecommitdiffstats
path: root/src/error.rs
blob: c7c867c3f90563cd6717a5bc792f7121debbdb9a (plain) (tree)
1
2
3
4
5
6
7
8
9



                                        
                           
 
                
                
               


                        
               

                     




                     
               
                  
                      
                   
                        
                    
                    





                                      

                

 
                                                




                                                   
                                         




                                               
                                

                                   


     
                                
                                    



                        

                                        

                    
 
 
                                 



                                    
use std::str::Utf8Error;

use rsasl::mechname::MechanismNameError;

use crate::jid::ParseError;

#[derive(Debug)]
pub enum Error {
    Connection,
    BadStream,
    StartTlsUnavailable,
    TlsNegotiation,
    Utf8Decode,
    NoFeatures,
    UnknownNamespace,
    UnknownAttribute,
    NoID,
    NoType,
    IDMismatch,
    BindError,
    ParseError,
    UnexpectedEnd,
    UnexpectedElement,
    UnexpectedText,
    XML(peanuts::Error),
    SASL(SASLError),
    JID(ParseError),
}

#[derive(Debug)]
pub enum SASLError {
    SASL(rsasl::prelude::SASLError),
    MechanismName(MechanismNameError),
    NoChallenge,
    NoSuccess,
}

impl From<rsasl::prelude::SASLError> for Error {
    fn from(e: rsasl::prelude::SASLError) -> Self {
        Self::SASL(SASLError::SASL(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)
    }
}