Skip to content

Commit

Permalink
feat(AsyncClient): remove code exposing flume errors in `ClientErro…
Browse files Browse the repository at this point in the history
…r` (bytebeamio#420)

* feat: remove code exposing flume errors in `ClientError` to simplify API surfaces and not reveal irrelevant internal details
* docs: add changelog entry

Signed-off-by: Devdutt Shenoi <devdutt@bytebeam.io>

Issue: 419

Attribute: @de-sh
  • Loading branch information
de-sh authored Aug 10, 2022
1 parent dec656f commit f6527c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
----------------
rumqttc
-----------
- Change variants in `ClientError` to not expose dependence on flume/`SendError`.

-----------

### R13
----------------
rumqttc v0.13.0
Expand Down
24 changes: 21 additions & 3 deletions rumqttc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,33 @@ use tokio::runtime::Runtime;
#[derive(Debug, thiserror::Error)]
pub enum ClientError {
#[error("Failed to send cancel request to eventloop")]
Cancel(#[from] SendError<()>),
Cancel,
#[error("Failed to send mqtt requests to eventloop")]
Request(#[from] SendError<Request>),
Request(Request),
#[error("Failed to send mqtt requests to eventloop")]
TryRequest(#[from] TrySendError<Request>),
TryRequest(Request),
#[error("Serialization error: {0}")]
Mqtt4(#[from] mqttbytes::Error),
}

impl From<SendError<()>> for ClientError {
fn from(_: SendError<()>) -> Self {
Self::Cancel
}
}

impl From<SendError<Request>> for ClientError {
fn from(e: SendError<Request>) -> Self {
Self::Request(e.into_inner())
}
}

impl From<TrySendError<Request>> for ClientError {
fn from(e: TrySendError<Request>) -> Self {
Self::TryRequest(e.into_inner())
}
}

/// `AsyncClient` to communicate with MQTT `Eventloop`
/// This is cloneable and can be used to asynchronously Publish, Subscribe.
#[derive(Clone, Debug)]
Expand Down

0 comments on commit f6527c9

Please sign in to comment.