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

Simplify SendError::MessageTooLarge #69

Merged
merged 1 commit into from
Apr 3, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- `SendError::MessageTooLarge` no longer contains the underlying error,
`std::num::TryFromIntError`, since it does not provide any useful information.

### Removed

- `RequestCode::Forward` and `message::send_forward_request`, since forwarding
Expand Down
8 changes: 4 additions & 4 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use bincode::Options;
use quinn::{RecvStream, SendStream};
use serde::{Deserialize, Serialize};
use std::{mem, num::TryFromIntError};
use std::mem;
use thiserror::Error;

/// The error type for receiving and deserializing a frame.
Expand Down Expand Up @@ -60,7 +60,7 @@ pub enum SendError {
#[error("failed serializing message")]
SerializationFailure(#[from] bincode::Error),
#[error("message is too large")]
MessageTooLarge(#[from] TryFromIntError),
MessageTooLarge,
#[error("failed to write to a stream")]
WriteError(#[from] quinn::WriteError),
}
Expand All @@ -80,7 +80,7 @@ where
{
buf.resize(mem::size_of::<u32>(), 0);
bincode::DefaultOptions::new().serialize_into(&mut *buf, &msg)?;
let len = u32::try_from(buf.len() - 4)?;
let len = u32::try_from(buf.len() - 4).map_err(|_| SendError::MessageTooLarge)?;
buf[..mem::size_of::<u32>()].clone_from_slice(&len.to_be_bytes());
send.write_all(buf).await?;
buf.clear();
Expand All @@ -94,7 +94,7 @@ where
/// * `SendError::MessageTooLarge`: if the message is too large
/// * `SendError::WriteError`: if the message could not be written
pub async fn send_raw(send: &mut SendStream, buf: &[u8]) -> Result<(), SendError> {
let len = u32::try_from(buf.len())?;
let len = u32::try_from(buf.len()).map_err(|_| SendError::MessageTooLarge)?;
send.write_all(&len.to_be_bytes()).await?;
send.write_all(buf).await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl From<SendError> for HandshakeError {
fn from(e: SendError) -> Self {
match e {
SendError::SerializationFailure(e) => HandshakeError::SerializationFailure(e),
SendError::MessageTooLarge(_) => HandshakeError::MessageTooLarge,
SendError::MessageTooLarge => HandshakeError::MessageTooLarge,
SendError::WriteError(e) => HandshakeError::WriteError(e),
}
}
Expand Down