Skip to content

Commit

Permalink
Replace manual Error type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini authored and Jarema committed Jun 27, 2023
1 parent 5ab4c5d commit c2c3b23
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions async-nats/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static VERSION_RE: Lazy<Regex> =
/// [`Client::publish_with_reply`] or [`Client::publish_with_reply_and_headers`] functions.
#[derive(Debug, Error)]
#[error("failed to publish message: {0}")]
pub struct PublishError(#[source] Box<dyn std::error::Error + Send + Sync>);
pub struct PublishError(#[source] crate::Error);

impl From<tokio::sync::mpsc::error::SendError<Command>> for PublishError {
fn from(err: tokio::sync::mpsc::error::SendError<Command>) -> Self {
Expand Down Expand Up @@ -601,7 +601,7 @@ impl Request {

#[derive(Error, Debug)]
#[error("failed to send subscribe: {0}")]
pub struct SubscribeError(#[source] Box<dyn std::error::Error + Sync + Send>);
pub struct SubscribeError(#[source] crate::Error);

impl From<tokio::sync::mpsc::error::SendError<Command>> for SubscribeError {
fn from(err: tokio::sync::mpsc::error::SendError<Command>) -> Self {
Expand All @@ -625,7 +625,7 @@ pub enum RequestErrorKind {
#[derive(Debug)]
pub struct RequestError {
kind: RequestErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(RequestError, RequestErrorKind);
Expand All @@ -645,7 +645,7 @@ impl Display for RequestError {
#[derive(Debug)]
pub struct FlushError {
kind: FlushErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(FlushError, FlushErrorKind);
Expand Down
2 changes: 1 addition & 1 deletion async-nats/src/jetstream/consumer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn is_default<T: Default + Eq>(t: &T) -> bool {
#[derive(Debug)]
pub struct StreamError {
kind: StreamErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}
crate::error_impls!(StreamError, StreamErrorKind);

Expand Down
8 changes: 4 additions & 4 deletions async-nats/src/jetstream/consumer/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl Stream {
#[derive(Debug)]
pub struct OrderedError {
kind: OrderedErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

impl std::fmt::Display for OrderedError {
Expand Down Expand Up @@ -1047,7 +1047,7 @@ pub enum OrderedErrorKind {
#[derive(Debug)]
pub struct MessagesError {
kind: MessagesErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

impl std::fmt::Display for MessagesError {
Expand Down Expand Up @@ -2204,7 +2204,7 @@ impl FromConsumer for Config {
#[derive(Debug)]
pub(crate) struct BatchRequestError {
kind: BatchRequestErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}
crate::error_impls!(BatchRequestError, BatchRequestErrorKind);

Expand Down Expand Up @@ -2234,7 +2234,7 @@ pub(crate) enum BatchRequestErrorKind {
#[derive(Debug)]
pub struct ConsumerRecreateError {
kind: ConsumerRecreateErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(ConsumerRecreateError, ConsumerRecreateErrorKind);
Expand Down
6 changes: 3 additions & 3 deletions async-nats/src/jetstream/consumer/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ impl<'a> futures::Stream for Ordered<'a> {
#[derive(Debug)]
pub struct OrderedError {
kind: OrderedErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

impl std::fmt::Display for OrderedError {
Expand Down Expand Up @@ -766,7 +766,7 @@ pub enum OrderedErrorKind {
#[derive(Debug)]
pub struct MessagesError {
kind: MessagesErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

impl std::fmt::Display for MessagesError {
Expand All @@ -793,7 +793,7 @@ pub enum MessagesErrorKind {
#[derive(Debug)]
pub struct ConsumerRecreateError {
kind: ConsumerRecreateErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(ConsumerRecreateError, ConsumerRecreateErrorKind);
Expand Down
16 changes: 8 additions & 8 deletions async-nats/src/jetstream/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ impl Context {
#[derive(Debug)]
pub struct PublishError {
kind: PublishErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(PublishError, PublishErrorKind);
Expand Down Expand Up @@ -1126,7 +1126,7 @@ type PageInfoRequest<'a> = BoxFuture<'a, Result<StreamInfoPage, RequestError>>;
#[derive(Debug)]
pub struct StreamsError {
kind: RequestErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}
crate::error_impls!(StreamsError, RequestErrorKind);

Expand Down Expand Up @@ -1274,7 +1274,7 @@ impl Publish {
#[derive(Debug)]
pub struct RequestError {
kind: RequestErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(RequestError, RequestErrorKind);
Expand Down Expand Up @@ -1326,7 +1326,7 @@ pub enum RequestErrorKind {
#[derive(Debug)]
pub struct CreateStreamError {
kind: CreateStreamErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(CreateStreamError, CreateStreamErrorKind);
Expand Down Expand Up @@ -1392,7 +1392,7 @@ pub enum CreateStreamErrorKind {
#[derive(Debug)]
pub struct GetStreamError {
kind: GetStreamErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

crate::error_impls!(GetStreamError, GetStreamErrorKind);
Expand Down Expand Up @@ -1424,7 +1424,7 @@ pub type DeleteStreamErrorKind = GetStreamErrorKind;
#[derive(Debug)]
pub struct KeyValueError {
kind: KeyValueErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

#[derive(Debug, Clone, Copy, PartialEq)]
Expand All @@ -1451,7 +1451,7 @@ impl Display for KeyValueError {
#[derive(Debug)]
pub struct CreateKeyValueError {
kind: CreateKeyValueErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -1488,7 +1488,7 @@ pub type CreateObjectStoreErrorKind = CreateKeyValueErrorKind;
#[derive(Debug)]
pub struct ObjectStoreError {
kind: ObjectStoreErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}
crate::error_impls!(ObjectStoreError, ObjectStoreErrorKind);

Expand Down
10 changes: 5 additions & 5 deletions async-nats/src/jetstream/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub type InfoError = RequestError;
#[derive(Debug)]
pub struct DirectGetError {
kind: DirectGetErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}
crate::error_impls!(DirectGetError, DirectGetErrorKind);

Expand Down Expand Up @@ -101,7 +101,7 @@ impl From<serde_json::Error> for DirectGetError {
#[derive(Debug)]
pub struct DeleteMessageError {
kind: DeleteMessageErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -1541,7 +1541,7 @@ where
#[derive(Debug)]
pub struct PurgeError {
kind: PurgeErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -1761,7 +1761,7 @@ impl futures::Stream for Consumers<'_> {

#[derive(Debug)]
pub struct LastRawMessageError {
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
kind: LastRawMessageErrorKind,
}
crate::error_impls!(LastRawMessageError, LastRawMessageErrorKind);
Expand Down Expand Up @@ -1807,7 +1807,7 @@ pub enum LastRawMessageErrorKind {
#[derive(Debug)]
pub struct ConsumerError {
pub kind: ConsumerErrorKind,
pub source: Option<Box<dyn std::error::Error + Send + Sync>>,
pub source: Option<crate::Error>,
}

crate::error_impls!(ConsumerError, ConsumerErrorKind);
Expand Down
6 changes: 3 additions & 3 deletions async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ pub enum ConnectErrorKind {
#[derive(Debug, Error)]
pub struct ConnectError {
kind: ConnectErrorKind,
source: Option<Box<dyn std::error::Error + Send + Sync>>,
source: Option<crate::Error>,
}

impl Display for ConnectError {
Expand All @@ -868,7 +868,7 @@ impl Display for ConnectError {
impl ConnectError {
fn with_source<E>(kind: ConnectErrorKind, source: E) -> ConnectError
where
E: Into<Box<dyn std::error::Error + Sync + Send>>,
E: Into<crate::Error>,
{
ConnectError {
kind,
Expand Down Expand Up @@ -1322,7 +1322,7 @@ macro_rules! error_impls {
#[allow(unreachable_pub)]
pub(crate) fn with_source<S>(kind: $k, source: S) -> $t
where
S: Into<Box<dyn std::error::Error + Sync + Send>>,
S: Into<crate::Error>,
{
Self {
kind,
Expand Down

0 comments on commit c2c3b23

Please sign in to comment.