Skip to content

Commit

Permalink
refactor!: Use SerializationError for too long messages
Browse files Browse the repository at this point in the history
This will allow merging the `SendError` and `RecvError` types.

BREAKING CHANGE: The `SendError::TooLong` variant has been removed. The
same condition (attempting to send a message longer than `u32::MAX`
bytes) will now return `SendError::Serialization`.
  • Loading branch information
Chris Connelly authored and connec committed Aug 27, 2021
1 parent c2905ea commit 5bf79c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ pub enum SendError {
/// Limitations in the serde API mean we cannot verify this statically, and we don't want to
/// introduce potential panics.
#[error("Failed to serialize message")]
Serialization(#[source] SerializationError),

/// The serialized message is too long (max: 4 GiB).
#[error("The serialized message is too long ({0} bytes, max: 4 GiB)")]
TooLong(usize),
Serialization(#[from] SerializationError),

/// Connection was lost when trying to send a message.
#[error("Connection was lost when trying to send a message")]
Expand Down
6 changes: 5 additions & 1 deletion src/wire_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ struct MsgHeader {
impl MsgHeader {
fn new(msg: &Bytes, usr_msg_flag: u8) -> Result<Self, SendError> {
match u32::try_from(msg.len()) {
Err(_) => Err(SendError::TooLong(msg.len())),
Err(_) => Err(SerializationError::new(format!(
"The serialized message is too long ({} bytes, max: 4 GiB)",
msg.len()
))
.into()),
Ok(data_len) => Ok(Self {
version: MSG_PROTOCOL_VERSION,
data_len,
Expand Down

0 comments on commit 5bf79c1

Please sign in to comment.