Remove the derive-error dependency.
It depends on a way too old syn crate, let’s drop it.
This commit is contained in:
parent
d173254483
commit
ed28ba1a7d
3 changed files with 105 additions and 13 deletions
|
@ -26,4 +26,3 @@ trust-dns-proto = "0.7"
|
||||||
xmpp-parsers = "0.13"
|
xmpp-parsers = "0.13"
|
||||||
idna = "0.1"
|
idna = "0.1"
|
||||||
quick-xml = "0.13"
|
quick-xml = "0.13"
|
||||||
derive-error = "0.0.4"
|
|
||||||
|
|
114
src/error.rs
114
src/error.rs
|
@ -11,7 +11,7 @@ use xmpp_parsers::Error as ParsersError;
|
||||||
use xmpp_parsers::sasl::DefinedCondition as SaslDefinedCondition;
|
use xmpp_parsers::sasl::DefinedCondition as SaslDefinedCondition;
|
||||||
|
|
||||||
/// Top-level error type
|
/// Top-level error type
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// I/O error
|
/// I/O error
|
||||||
Io(IoError),
|
Io(IoError),
|
||||||
|
@ -32,8 +32,53 @@ pub enum Error {
|
||||||
InvalidState,
|
InvalidState,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::Io(e) => write!(fmt, "IO error: {}", e),
|
||||||
|
Error::Connection(e) => write!(fmt, "connection error: {}", e),
|
||||||
|
Error::Idna => write!(fmt, "IDNA error"),
|
||||||
|
Error::Protocol(e) => write!(fmt, "protocol error: {}", e),
|
||||||
|
Error::Auth(e) => write!(fmt, "authentication error: {}", e),
|
||||||
|
Error::Tls(e) => write!(fmt, "TLS error: {}", e),
|
||||||
|
Error::Disconnected => write!(fmt, "disconnected"),
|
||||||
|
Error::InvalidState => write!(fmt, "invalid state"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<IoError> for Error {
|
||||||
|
fn from(e: IoError) -> Self {
|
||||||
|
Error::Io(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ConnecterError> for Error {
|
||||||
|
fn from(e: ConnecterError) -> Self {
|
||||||
|
Error::Connection(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ProtocolError> for Error {
|
||||||
|
fn from(e: ProtocolError) -> Self {
|
||||||
|
Error::Protocol(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AuthError> for Error {
|
||||||
|
fn from(e: AuthError) -> Self {
|
||||||
|
Error::Auth(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TlsError> for Error {
|
||||||
|
fn from(e: TlsError) -> Self {
|
||||||
|
Error::Tls(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Causes for stream parsing errors
|
/// Causes for stream parsing errors
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum ParserError {
|
pub enum ParserError {
|
||||||
/// Encoding error
|
/// Encoding error
|
||||||
Utf8(Utf8Error),
|
Utf8(Utf8Error),
|
||||||
|
@ -42,7 +87,24 @@ pub enum ParserError {
|
||||||
/// Illegal `</>`
|
/// Illegal `</>`
|
||||||
ShortTag,
|
ShortTag,
|
||||||
/// Required by `impl Decoder`
|
/// Required by `impl Decoder`
|
||||||
IO(IoError),
|
Io(IoError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ParserError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
ParserError::Utf8(e) => write!(fmt, "UTF-8 error: {}", e),
|
||||||
|
ParserError::Parse(e) => write!(fmt, "parse error: {}", e),
|
||||||
|
ParserError::ShortTag => write!(fmt, "short tag"),
|
||||||
|
ParserError::Io(e) => write!(fmt, "IO error: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<IoError> for ParserError {
|
||||||
|
fn from(e: IoError) -> Self {
|
||||||
|
ParserError::Io(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ParserError> for Error {
|
impl From<ParserError> for Error {
|
||||||
|
@ -71,12 +133,11 @@ impl fmt::Display for ParseError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// XMPP protocol-level error
|
/// XMPP protocol-level error
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum ProtocolError {
|
pub enum ProtocolError {
|
||||||
/// XML parser error
|
/// XML parser error
|
||||||
Parser(ParserError),
|
Parser(ParserError),
|
||||||
/// Error with expected stanza schema
|
/// Error with expected stanza schema
|
||||||
#[error(non_std)]
|
|
||||||
Parsers(ParsersError),
|
Parsers(ParsersError),
|
||||||
/// No TLS available
|
/// No TLS available
|
||||||
NoTls,
|
NoTls,
|
||||||
|
@ -92,22 +153,57 @@ pub enum ProtocolError {
|
||||||
InvalidStreamStart,
|
InvalidStreamStart,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ProtocolError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
ProtocolError::Parser(e) => write!(fmt, "XML parser error: {}", e),
|
||||||
|
ProtocolError::Parsers(e) => write!(fmt, "error with expected stanza schema: {}", e),
|
||||||
|
ProtocolError::NoTls => write!(fmt, "no TLS available"),
|
||||||
|
ProtocolError::InvalidBindResponse => write!(fmt, "invalid response to resource binding"),
|
||||||
|
ProtocolError::NoStreamNamespace => write!(fmt, "no xmlns attribute in <stream:stream>"),
|
||||||
|
ProtocolError::NoStreamId => write!(fmt, "no id attribute in <stream:stream>"),
|
||||||
|
ProtocolError::InvalidToken => write!(fmt, "encountered an unexpected XML token"),
|
||||||
|
ProtocolError::InvalidStreamStart => write!(fmt, "unexpected <stream:stream>"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParserError> for ProtocolError {
|
||||||
|
fn from(e: ParserError) -> Self {
|
||||||
|
ProtocolError::Parser(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParsersError> for ProtocolError {
|
||||||
|
fn from(e: ParsersError) -> Self {
|
||||||
|
ProtocolError::Parsers(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Authentication error
|
/// Authentication error
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum AuthError {
|
pub enum AuthError {
|
||||||
/// No matching SASL mechanism available
|
/// No matching SASL mechanism available
|
||||||
NoMechanism,
|
NoMechanism,
|
||||||
/// Local SASL implementation error
|
/// Local SASL implementation error
|
||||||
#[error(no_from, non_std, msg_embedded)]
|
|
||||||
Sasl(String),
|
Sasl(String),
|
||||||
/// Failure from server
|
/// Failure from server
|
||||||
#[error(non_std)]
|
|
||||||
Fail(SaslDefinedCondition),
|
Fail(SaslDefinedCondition),
|
||||||
/// Component authentication failure
|
/// Component authentication failure
|
||||||
#[error(no_from)]
|
|
||||||
ComponentFail,
|
ComponentFail,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for AuthError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
AuthError::NoMechanism => write!(fmt, "no matching SASL mechanism available"),
|
||||||
|
AuthError::Sasl(s) => write!(fmt, "local SASL implementation error: {}", s),
|
||||||
|
AuthError::Fail(c) => write!(fmt, "failure from the server: {:?}", c),
|
||||||
|
AuthError::ComponentFail => write!(fmt, "component authentication failure"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Error establishing connection
|
/// Error establishing connection
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ConnecterError {
|
pub enum ConnecterError {
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
//! XMPP implementation with asynchronous I/O using Tokio.
|
//! XMPP implementation with asynchronous I/O using Tokio.
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate derive_error;
|
|
||||||
|
|
||||||
mod starttls;
|
mod starttls;
|
||||||
mod stream_start;
|
mod stream_start;
|
||||||
pub mod xmpp_codec;
|
pub mod xmpp_codec;
|
||||||
|
|
Loading…
Reference in a new issue