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

Use From<ReadError> #82

Merged
merged 1 commit into from
May 21, 2024
Merged
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
77 changes: 1 addition & 76 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,82 +52,7 @@
fn from_read_exact_error_to_io_error(e: quinn::ReadExactError) -> io::Error {
match e {
quinn::ReadExactError::FinishedEarly(_) => io::Error::from(io::ErrorKind::UnexpectedEof),
quinn::ReadExactError::ReadError(e) => from_read_error_to_io_error(e),
}
}

fn from_read_error_to_io_error(e: quinn::ReadError) -> io::Error {
use quinn::ReadError;

match e {
ReadError::Reset(_) => io::Error::from(io::ErrorKind::ConnectionReset),
ReadError::ConnectionLost(e) => from_connection_error_to_io_error(e),
ReadError::ClosedStream => io::Error::new(io::ErrorKind::Other, "closed stream"),
ReadError::IllegalOrderedRead => {
io::Error::new(io::ErrorKind::InvalidInput, "illegal ordered read")
}
ReadError::ZeroRttRejected => {
io::Error::new(io::ErrorKind::ConnectionRefused, "0-RTT rejected")
}
}
}

fn from_connection_error_to_io_error(e: quinn::ConnectionError) -> io::Error {
use quinn::ConnectionError;

match e {
ConnectionError::VersionMismatch => io::Error::from(io::ErrorKind::ConnectionRefused),
ConnectionError::TransportError(e) => from_transport_error_to_io_error(e),
ConnectionError::ConnectionClosed(e) => io::Error::new(
io::ErrorKind::ConnectionAborted,
String::from_utf8_lossy(&e.reason),
),
ConnectionError::ApplicationClosed(e) => io::Error::new(
io::ErrorKind::ConnectionAborted,
String::from_utf8_lossy(&e.reason),
),
ConnectionError::Reset => io::Error::from(io::ErrorKind::ConnectionReset),
ConnectionError::TimedOut => io::Error::from(io::ErrorKind::TimedOut),
ConnectionError::LocallyClosed => {
io::Error::new(io::ErrorKind::Other, "connection locally closed")
}
ConnectionError::CidsExhausted => {
io::Error::new(io::ErrorKind::Other, "cid space exhausted")
}
}
}

fn from_transport_error_to_io_error(e: quinn_proto::TransportError) -> io::Error {
use quinn_proto::TransportErrorCode;

match e.code {
TransportErrorCode::CONNECTION_REFUSED => {
io::Error::new(io::ErrorKind::ConnectionRefused, e.reason)
}
TransportErrorCode::CONNECTION_ID_LIMIT_ERROR
| TransportErrorCode::CRYPTO_BUFFER_EXCEEDED
| TransportErrorCode::FINAL_SIZE_ERROR
| TransportErrorCode::FLOW_CONTROL_ERROR
| TransportErrorCode::FRAME_ENCODING_ERROR
| TransportErrorCode::INVALID_TOKEN
| TransportErrorCode::PROTOCOL_VIOLATION
| TransportErrorCode::STREAM_LIMIT_ERROR
| TransportErrorCode::STREAM_STATE_ERROR
| TransportErrorCode::TRANSPORT_PARAMETER_ERROR => {
io::Error::new(io::ErrorKind::InvalidData, e.reason)
}
TransportErrorCode::NO_VIABLE_PATH => {
// TODO: Use `io::ErrorKind::HostUnreachable` when it is stabilized
io::Error::new(io::ErrorKind::Other, e.reason)
}
_ => {
// * TransportErrorCode::AEAD_LIMIT_REACHED
// * TransportErrorCode::APPLICATION_ERROR
// * TransportErrorCode::INTERNAL_ERROR
// * TransportErrorCode::KEY_UPDATE_ERROR
// * TransportErrorCode::NO_ERROR
io::Error::new(io::ErrorKind::Other, e.reason)
}
quinn::ReadExactError::ReadError(e) => e.into(),

Check warning on line 55 in src/frame.rs

View check run for this annotation

Codecov / codecov/patch

src/frame.rs#L55

Added line #L55 was not covered by tests
}
}

Expand Down