From 34796c90d402a7af69f68b853927c00353af5865 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Sun, 4 Aug 2024 17:32:12 +0200 Subject: [PATCH] Only expose one error type in crate root --- tokio-xmpp/ChangeLog | 2 ++ tokio-xmpp/src/client/async_client.rs | 2 +- tokio-xmpp/src/client/auth.rs | 2 +- tokio-xmpp/src/client/bind.rs | 2 +- tokio-xmpp/src/component/auth.rs | 2 +- tokio-xmpp/src/lib.rs | 6 ++++-- tokio-xmpp/src/starttls/mod.rs | 5 +++-- tokio-xmpp/src/stream_start.rs | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tokio-xmpp/ChangeLog b/tokio-xmpp/ChangeLog index 924ca65e..205f2af9 100644 --- a/tokio-xmpp/ChangeLog +++ b/tokio-xmpp/ChangeLog @@ -5,6 +5,8 @@ XXXX-YY-ZZ RELEASER - Removed StreamFeatures from this crate, replaced with xmpp_parsers::stream_features::StreamFeatures (!400) - `starttls::error::ConnectorError` variants have been merged with `starttls::error::Error`, except `ConnectorError::AllFailed` which was not used and has been completely removed (!418) + - `ProtocolError` and `AuthError` are no longer exported in crate root; + access them from `error` module (!423) Version 4.0.0: 2024-07-26 Maxime “pep” Buquet diff --git a/tokio-xmpp/src/client/async_client.rs b/tokio-xmpp/src/client/async_client.rs index a79d8f83..c2684a3c 100644 --- a/tokio-xmpp/src/client/async_client.rs +++ b/tokio-xmpp/src/client/async_client.rs @@ -8,10 +8,10 @@ use xmpp_parsers::{jid::Jid, ns, stream_features::StreamFeatures}; use super::connect::client_login; use crate::connect::{AsyncReadAndWrite, ServerConnector}; +use crate::error::{Error, ProtocolError}; use crate::event::Event; use crate::xmpp_codec::Packet; use crate::xmpp_stream::{add_stanza_id, XMPPStream}; -use crate::{Error, ProtocolError}; /// XMPP client connection and state /// diff --git a/tokio-xmpp/src/client/auth.rs b/tokio-xmpp/src/client/auth.rs index 9c7f35de..437ec799 100644 --- a/tokio-xmpp/src/client/auth.rs +++ b/tokio-xmpp/src/client/auth.rs @@ -8,9 +8,9 @@ use std::str::FromStr; use tokio::io::{AsyncRead, AsyncWrite}; use xmpp_parsers::sasl::{Auth, Challenge, Failure, Mechanism as XMPPMechanism, Response, Success}; +use crate::error::{AuthError, Error, ProtocolError}; use crate::xmpp_codec::Packet; use crate::xmpp_stream::XMPPStream; -use crate::{AuthError, Error, ProtocolError}; pub async fn auth( mut stream: XMPPStream, diff --git a/tokio-xmpp/src/client/bind.rs b/tokio-xmpp/src/client/bind.rs index ca79ff63..de791a8f 100644 --- a/tokio-xmpp/src/client/bind.rs +++ b/tokio-xmpp/src/client/bind.rs @@ -3,9 +3,9 @@ use tokio::io::{AsyncRead, AsyncWrite}; use xmpp_parsers::bind::{BindQuery, BindResponse}; use xmpp_parsers::iq::{Iq, IqType}; +use crate::error::{Error, ProtocolError}; use crate::xmpp_codec::Packet; use crate::xmpp_stream::XMPPStream; -use crate::{Error, ProtocolError}; const BIND_REQ_ID: &str = "resource-bind"; diff --git a/tokio-xmpp/src/component/auth.rs b/tokio-xmpp/src/component/auth.rs index 36f2bf7d..370c77a1 100644 --- a/tokio-xmpp/src/component/auth.rs +++ b/tokio-xmpp/src/component/auth.rs @@ -2,9 +2,9 @@ use futures::stream::StreamExt; use tokio::io::{AsyncRead, AsyncWrite}; use xmpp_parsers::{component::Handshake, ns}; +use crate::error::{AuthError, Error}; use crate::xmpp_codec::Packet; use crate::xmpp_stream::XMPPStream; -use crate::{AuthError, Error}; pub async fn auth( stream: &mut XMPPStream, diff --git a/tokio-xmpp/src/lib.rs b/tokio-xmpp/src/lib.rs index 89fb249a..b922cd65 100644 --- a/tokio-xmpp/src/lib.rs +++ b/tokio-xmpp/src/lib.rs @@ -38,8 +38,10 @@ pub use client::{ }; mod component; pub use crate::component::Component; -mod error; -pub use crate::error::{AuthError, Error, ProtocolError}; +/// Detailed error types +pub mod error; +/// Generic tokio_xmpp Error +pub use crate::error::Error; // Re-exports pub use minidom; diff --git a/tokio-xmpp/src/starttls/mod.rs b/tokio-xmpp/src/starttls/mod.rs index 92d952c4..277d0905 100644 --- a/tokio-xmpp/src/starttls/mod.rs +++ b/tokio-xmpp/src/starttls/mod.rs @@ -27,6 +27,7 @@ use tokio::{ }; use xmpp_parsers::{jid::Jid, ns}; +use crate::error::ProtocolError; use crate::{connect::ServerConnector, xmpp_codec::Packet, AsyncClient, SimpleClient}; use crate::{connect::ServerConnectorError, xmpp_stream::XMPPStream}; @@ -80,7 +81,7 @@ impl ServerConnector for ServerConfig { // Encrypted XMPPStream Ok(XMPPStream::start(tls_stream, jid.clone(), ns.to_owned()).await?) } else { - return Err(crate::Error::Protocol(crate::ProtocolError::NoTls).into()); + return Err(crate::Error::Protocol(ProtocolError::NoTls).into()); } } @@ -159,7 +160,7 @@ pub async fn starttls( Some(Ok(Packet::Text(_))) => {} Some(Err(e)) => return Err(e.into()), _ => { - return Err(crate::Error::Protocol(crate::ProtocolError::NoTls).into()); + return Err(crate::Error::Protocol(ProtocolError::NoTls).into()); } } } diff --git a/tokio-xmpp/src/stream_start.rs b/tokio-xmpp/src/stream_start.rs index effaf20d..f8a90338 100644 --- a/tokio-xmpp/src/stream_start.rs +++ b/tokio-xmpp/src/stream_start.rs @@ -3,9 +3,9 @@ use tokio::io::{AsyncRead, AsyncWrite}; use tokio_util::codec::Framed; use xmpp_parsers::{jid::Jid, ns, stream_features::StreamFeatures}; +use crate::error::{Error, ProtocolError}; use crate::xmpp_codec::{Packet, XmppCodec}; use crate::xmpp_stream::XMPPStream; -use crate::{Error, ProtocolError}; /// Sends a ``, then wait for one from the server, and /// construct an XMPPStream.