Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QueueError::PayloadTooLarge #71

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# unreleased

## Breaking changes

- Remove `QueueError::Unsupported`
- This variant was never constructed inside `omniqueue`

## Additions

- Add `QueueError::PayloadTooLarge`

# 0.2.0

This release is a big one, and we are considering omniqueue out of early development now.
Expand Down
1 change: 1 addition & 0 deletions omniqueue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ azure_storage = { version = "0.19.0", optional = true }
azure_storage_queues = { version = "0.19.0", optional = true }
bb8 = { version = "0.8", optional = true }
bb8-redis = { version = "0.14.0", optional = true }
bytesize = "1.3.0"
futures-util = { version = "0.3.28", default-features = false, features = ["async-await", "std"], optional = true }
google-cloud-googleapis = { version = "0.12.0", optional = true }
google-cloud-pubsub = { version = "0.23.0", optional = true }
Expand Down
7 changes: 4 additions & 3 deletions omniqueue/src/backends/sqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ impl SqsProducer {

pub async fn send_raw_scheduled(&self, payload: &str, delay: Duration) -> Result<()> {
if payload.len() > MAX_PAYLOAD_SIZE {
return Err(QueueError::Generic(
"payload exceeds SQS size limit of 256K".into(),
));
return Err(QueueError::PayloadTooLarge {
limit: MAX_PAYLOAD_SIZE,
actual: payload.len(),
});
}

self.client
Expand Down
15 changes: 11 additions & 4 deletions omniqueue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

use std::fmt::Debug;

use bytesize::ByteSize;
use thiserror::Error;

#[macro_use]
Expand Down Expand Up @@ -117,15 +118,21 @@ pub enum QueueError {

#[error("no data was received from the queue")]
NoData,

#[error("(de)serialization error")]
Serde(#[from] serde_json::Error),

#[error("{0}")]
Generic(Box<dyn std::error::Error + Send + Sync>),
#[error("payload too large: {} > {}", ByteSize(*actual as u64), ByteSize(*limit as u64))]
PayloadTooLarge {
/// The size of the serialized message, in bytes.
actual: usize,

/// The message size limit of the queue, in bytes.
limit: usize,
},

#[error("{0}")]
#[deprecated = "This variant is never created inside omniqueue"]
Unsupported(&'static str),
Generic(Box<dyn std::error::Error + Send + Sync>),
}

impl QueueError {
Expand Down
Loading