Switch from err-derive to thiserror

thiserror is easier to use, has fewer dependencies and is more popular.
This commit is contained in:
Dirkjan Ochtman
2020-10-29 11:41:41 +01:00
committed by Benjamin Saunders
parent 766d20a592
commit 1bca0f7c2a
18 changed files with 110 additions and 125 deletions
+1 -1
View File
@@ -26,7 +26,6 @@ maintenance = { status = "experimental" }
[dependencies] [dependencies]
bytes = "0.5.2" bytes = "0.5.2"
err-derive = "0.2.3"
futures = "0.3.1" futures = "0.3.1"
futures-util = { version = "0.3", default-features = false } futures-util = { version = "0.3", default-features = false }
http = "0.2" http = "0.2"
@@ -36,6 +35,7 @@ pin-project = "^0.4.21"
quinn-proto = { path = "../quinn-proto", version = "0.6.0" } quinn-proto = { path = "../quinn-proto", version = "0.6.0" }
quinn = { path = "../quinn", version = "0.6.0", features = ["tls-rustls"] } quinn = { path = "../quinn", version = "0.6.0", features = ["tls-rustls"] }
rustls = { git = "https://github.com/ctz/rustls", rev = "fee894f7e030", features = ["quic"] } rustls = { git = "https://github.com/ctz/rustls", rev = "fee894f7e030", features = ["quic"] }
thiserror = "1.0.21"
tokio = "0.2.6" tokio = "0.2.6"
tokio-util = { version = "0.3.0", features = ["codec"] } tokio-util = { version = "0.3.0", features = ["codec"] }
tracing = "0.1.10" tracing = "0.1.10"
+16 -16
View File
@@ -108,9 +108,9 @@ mod qpack;
#[doc(hidden)] #[doc(hidden)]
pub mod qpack; pub mod qpack;
use err_derive::Error;
use quinn::{ApplicationClose, ConnectionError, ReadError, StoppedError, VarInt, WriteError}; use quinn::{ApplicationClose, ConnectionError, ReadError, StoppedError, VarInt, WriteError};
use std::{error::Error as StdError, io::ErrorKind}; use std::{error::Error as StdError, io::ErrorKind};
use thiserror::Error;
use proto::ErrorCode; use proto::ErrorCode;
@@ -121,49 +121,49 @@ pub type ZeroRttAccepted = quinn::ZeroRttAccepted;
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum Error { pub enum Error {
/// Cannot make a new request, bescause the connection is closing /// Cannot make a new request, bescause the connection is closing
#[error(display = "Connection is closing, resquest aborted")] #[error("Connection is closing, resquest aborted")]
Aborted, Aborted,
/// Protocol violation detected by the internal HTTP/3 protocol state machine /// Protocol violation detected by the internal HTTP/3 protocol state machine
#[error(display = "H3 protocol error: {:?}", _0)] #[error("H3 protocol error: {0:?}")]
Proto(proto::connection::Error), Proto(proto::connection::Error),
/// Error occurred at the `QUIC` level /// Error occurred at the `QUIC` level
#[error(display = "QUIC protocol error: {}", _0)] #[error("QUIC protocol error: {0}")]
Quic(quinn::ConnectionError), Quic(quinn::ConnectionError),
/// A `QUIC`-specific read error occurred /// A `QUIC`-specific read error occurred
#[error(display = "QUIC read error: {}", _0)] #[error("QUIC read error: {0}")]
Read(ReadError), Read(ReadError),
/// A `QUIC`-specific write error occurred /// A `QUIC`-specific write error occurred
#[error(display = "QUIC write error: {}", _0)] #[error("QUIC write error: {0}")]
Write(WriteError), Write(WriteError),
/// A `QUIC`-specific error occurred while polling for STOP_SENDING /// A `QUIC`-specific error occurred while polling for STOP_SENDING
#[error(display = "QUIC error while polling for STOP_SENDING: {}", _0)] #[error("QUIC error while polling for STOP_SENDING: {0}")]
Stopped(StoppedError), Stopped(StoppedError),
/// Programming error within the crate's code /// Programming error within the crate's code
#[error(display = "Internal error: {}", _0)] #[error("Internal error: {0}")]
Internal(String), Internal(String),
/// The peer's behavior was detected as incorrect or malicious /// The peer's behavior was detected as incorrect or malicious
#[error(display = "Incorrect peer behavior: {}", _0)] #[error("Incorrect peer behavior: {0}")]
Peer(String), Peer(String),
/// The peer tried to open an unidirectional stream with an unknown type code /// The peer tried to open an unidirectional stream with an unknown type code
#[error(display = "unknown stream type {}", _0)] #[error("unknown stream type {0}")]
UnknownStream(u64), UnknownStream(u64),
/// An IO error occurred /// An IO error occurred
#[error(display = "IO error: {}", _0)] #[error("IO error: {0}")]
Io(std::io::Error), Io(std::io::Error),
/// An overflow occurred into the `QPACK` decoder /// An overflow occurred into the `QPACK` decoder
#[error(display = "Overflow max data size")] #[error("Overflow max data size")]
Overflow, Overflow,
/// A future has been polled after it was already finished /// A future has been polled after it was already finished
#[error(display = "Polled after finished")] #[error("Polled after finished")]
Poll, Poll,
/// The peer issued an HTTP/3 error code and an optional text description /// The peer issued an HTTP/3 error code and an optional text description
#[error(display = "Http error: {:?}", _0)] #[error("Http error: {0:?}")]
Http(HttpError, Option<String>), Http(HttpError, Option<String>),
/// Header validity error from a client call /// Header validity error from a client call
#[error(display = "Header error: {:?}", _0)] #[error("Header error: {0:?}")]
Header(&'static str), Header(&'static str),
/// Polling the issued body data yielded an error /// Polling the issued body data yielded an error
#[error(display = "Polling body error: {}", _0)] #[error("Polling body error: {0}")]
Body(Box<dyn StdError + Send + Sync>), Body(Box<dyn StdError + Send + Sync>),
} }
+10 -10
View File
@@ -1,7 +1,7 @@
use bytes::{Buf, BufMut}; use bytes::{Buf, BufMut};
use std::{fmt, io::Cursor}; use std::{fmt, io::Cursor};
use err_derive::Error; use thiserror::Error;
use tracing::trace; use tracing::trace;
use super::{ use super::{
@@ -25,23 +25,23 @@ use super::{prefix_int, prefix_string};
#[derive(Debug, PartialEq, Error)] #[derive(Debug, PartialEq, Error)]
pub enum Error { pub enum Error {
#[error(display = "failed to parse integer: {:?}", _0)] #[error("failed to parse integer: {0:?}")]
InvalidInteger(prefix_int::Error), InvalidInteger(prefix_int::Error),
#[error(display = "failed to parse string: {:?}", _0)] #[error("failed to parse string: {0:?}")]
InvalidString(prefix_string::Error), InvalidString(prefix_string::Error),
#[error(display = "index is out of dynamic table bounds: {:?}", _0)] #[error("index is out of dynamic table bounds: {0:?}")]
InvalidIndex(vas::Error), InvalidIndex(vas::Error),
#[error(display = "dynamic table error: {}", _0)] #[error("dynamic table error: {0}")]
DynamicTableError(DynamicTableError), DynamicTableError(DynamicTableError),
#[error(display = "index '{}' is out of static table bounds", _0)] #[error("index '{}' is out of static table bounds", _0)]
InvalidStaticIndex(usize), InvalidStaticIndex(usize),
#[error(display = "invalid data prefix")] #[error("invalid data prefix")]
UnknownPrefix, UnknownPrefix,
#[error(display = "missing references from dynamic table to decode header block")] #[error("missing references from dynamic table to decode header block")]
MissingRefs(usize), MissingRefs(usize),
#[error(display = "header prefix contains invalid base index: {:?}", _0)] #[error("header prefix contains invalid base index: {0:?}")]
BadBaseIndex(isize), BadBaseIndex(isize),
#[error(display = "data is unexpectedly truncated")] #[error("data is unexpectedly truncated")]
UnexpectedEnd, UnexpectedEnd,
} }
+10 -13
View File
@@ -3,7 +3,7 @@ use std::{
collections::{btree_map::Entry as BTEntry, hash_map::Entry, BTreeMap, HashMap, VecDeque}, collections::{btree_map::Entry as BTEntry, hash_map::Entry, BTreeMap, HashMap, VecDeque},
}; };
use err_derive::Error; use thiserror::Error;
use super::{field::HeaderField, static_::StaticTable}; use super::{field::HeaderField, static_::StaticTable};
use crate::qpack::vas::{self, VirtualAddressSpace}; use crate::qpack::vas::{self, VirtualAddressSpace};
@@ -16,26 +16,23 @@ const SETTINGS_MAX_BLOCKED_STREAMS_MAX: usize = 65_535; // 2^16 - 1
#[derive(Debug, PartialEq, Error)] #[derive(Debug, PartialEq, Error)]
pub enum Error { pub enum Error {
#[error(display = "bad relative index: {}", _0)] #[error("bad relative index: {0}")]
BadRelativeIndex(usize), BadRelativeIndex(usize),
#[error(display = "bad post base index: {}", _0)] #[error("bad post base index: {0}")]
BadPostbaseIndex(usize), BadPostbaseIndex(usize),
#[error(display = "decoded index out of bounds: {}", _0)] #[error("decoded index out of bounds: {0}")]
BadIndex(usize), BadIndex(usize),
#[error(display = "tried to insert a field greater than dynamic table available size")] #[error("tried to insert a field greater than dynamic table available size")]
MaxTableSizeReached, MaxTableSizeReached,
#[error(display = "table size setting is greater than maximum authorized")] #[error("table size setting is greater than maximum authorized")]
MaximumTableSizeTooLarge, MaximumTableSizeTooLarge,
#[error(display = "max blocked stream setting is greater than maximum authorized")] #[error("max blocked stream setting is greater than maximum authorized")]
MaxBlockedStreamsTooLarge, MaxBlockedStreamsTooLarge,
#[error( #[error("stream id '{0}' is unknown or has already been acknowledged or canceled")]
display = "stream id '{}' is unknown or has already been acknowledged or canceled",
_0
)]
UnknownStreamId(u64), UnknownStreamId(u64),
#[error(display = "tried to acknowledge encoder stream but no encoder data has been sent")] #[error("tried to acknowledge encoder stream but no encoder data has been sent")]
NoTrackingData, NoTrackingData,
#[error(display = "internal reference tracking error")] #[error("internal reference tracking error")]
InvalidTrackingCount, InvalidTrackingCount,
} }
+5 -5
View File
@@ -2,7 +2,7 @@ use std::{cmp, io::Cursor};
use bytes::{Buf, BufMut}; use bytes::{Buf, BufMut};
use err_derive::Error; use thiserror::Error;
use super::{ use super::{
block::{ block::{
@@ -26,13 +26,13 @@ use super::{
#[derive(Debug, PartialEq, Error)] #[derive(Debug, PartialEq, Error)]
pub enum Error { pub enum Error {
#[error(display = "failed to insert in dynamic table: {}", _0)] #[error("failed to insert in dynamic table: {0}")]
Insertion(DynamicTableError), Insertion(DynamicTableError),
#[error(display = "prefixed string: {:?}", _0)] #[error("prefixed string: {0:?}")]
InvalidString(StringError), InvalidString(StringError),
#[error(display = "prefixed integer: {:?}", _0)] #[error("prefixed integer: {0:?}")]
InvalidInteger(IntError), InvalidInteger(IntError),
#[error(display = "invalid data prefix")] #[error("invalid data prefix")]
UnknownPrefix, UnknownPrefix,
} }
+1
View File
@@ -34,6 +34,7 @@ ring = { version = "0.16.7", optional = true }
rustls = { git = "https://github.com/ctz/rustls", rev = "fee894f7e030", features = ["quic"], optional = true } rustls = { git = "https://github.com/ctz/rustls", rev = "fee894f7e030", features = ["quic"], optional = true }
rustls-native-certs = { git = "https://github.com/kwantam/rustls-native-certs", rev = "52fc75ad4430", optional = true } rustls-native-certs = { git = "https://github.com/kwantam/rustls-native-certs", rev = "52fc75ad4430", optional = true }
slab = "0.4" slab = "0.4"
thiserror = "1.0.21"
tracing = "0.1.10" tracing = "0.1.10"
webpki = { version = "0.21", optional = true } webpki = { version = "0.21", optional = true }
+2 -2
View File
@@ -1,12 +1,12 @@
use std::net::{Ipv4Addr, Ipv6Addr}; use std::net::{Ipv4Addr, Ipv6Addr};
use bytes::{Buf, BufMut}; use bytes::{Buf, BufMut};
use err_derive::Error; use thiserror::Error;
use crate::VarInt; use crate::VarInt;
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)] #[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
#[error(display = "unexpected end of buffer")] #[error("unexpected end of buffer")]
pub struct UnexpectedEnd; pub struct UnexpectedEnd;
pub type Result<T> = ::std::result::Result<T, UnexpectedEnd>; pub type Result<T> = ::std::result::Result<T, UnexpectedEnd>;
+2 -2
View File
@@ -1,7 +1,7 @@
use std::{convert::TryInto, fmt, num::TryFromIntError, sync::Arc, time::Duration}; use std::{convert::TryInto, fmt, num::TryFromIntError, sync::Arc, time::Duration};
use err_derive::Error;
use rand::RngCore; use rand::RngCore;
use thiserror::Error;
#[cfg(feature = "rustls")] #[cfg(feature = "rustls")]
use crate::crypto::types::{Certificate, CertificateChain, PrivateKey}; use crate::crypto::types::{Certificate, CertificateChain, PrivateKey};
@@ -626,7 +626,7 @@ where
#[non_exhaustive] #[non_exhaustive]
pub enum ConfigError { pub enum ConfigError {
/// Value exceeds supported bounds /// Value exceeds supported bounds
#[error(display = "value exceeds supported bounds")] #[error("value exceeds supported bounds")]
OutOfBounds, OutOfBounds,
} }
+13 -19
View File
@@ -9,8 +9,8 @@ use std::{
}; };
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use err_derive::Error;
use rand::{rngs::StdRng, Rng, SeedableRng}; use rand::{rngs::StdRng, Rng, SeedableRng};
use thiserror::Error;
use tracing::{debug, error, trace, trace_span, warn}; use tracing::{debug, error, trace, trace_span, warn};
use crate::{ use crate::{
@@ -26,7 +26,7 @@ use crate::{
ConnectionEvent, ConnectionEventInner, ConnectionId, EcnCodepoint, EndpointEvent, ConnectionEvent, ConnectionEventInner, ConnectionId, EcnCodepoint, EndpointEvent,
EndpointEventInner, IssuedCid, EndpointEventInner, IssuedCid,
}, },
transport_parameters::{self, TransportParameters}, transport_parameters::TransportParameters,
Dir, Frame, Side, StreamId, Transmit, TransportError, TransportErrorCode, VarInt, Dir, Frame, Side, StreamId, Transmit, TransportError, TransportErrorCode, VarInt,
LOC_CID_COUNT, MAX_STREAM_COUNT, MIN_INITIAL_SIZE, MIN_MTU, RESET_TOKEN_SIZE, LOC_CID_COUNT, MAX_STREAM_COUNT, MIN_INITIAL_SIZE, MIN_MTU, RESET_TOKEN_SIZE,
TIMER_GRANULARITY, VERSION, TIMER_GRANULARITY, VERSION,
@@ -3010,25 +3010,25 @@ where
#[derive(Debug, Error, Clone, PartialEq, Eq)] #[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum ConnectionError { pub enum ConnectionError {
/// The peer doesn't implement any supported version. /// The peer doesn't implement any supported version.
#[error(display = "peer doesn't implement any supported version")] #[error("peer doesn't implement any supported version")]
VersionMismatch, VersionMismatch,
/// The peer violated the QUIC specification as understood by this implementation. /// The peer violated the QUIC specification as understood by this implementation.
#[error(display = "{}", _0)] #[error("{0}")]
TransportError(#[source] TransportError), TransportError(#[from] TransportError),
/// The peer's QUIC stack aborted the connection automatically. /// The peer's QUIC stack aborted the connection automatically.
#[error(display = "aborted by peer: {}", 0)] #[error("aborted by peer: {}", 0)]
ConnectionClosed(frame::ConnectionClose), ConnectionClosed(frame::ConnectionClose),
/// The peer closed the connection. /// The peer closed the connection.
#[error(display = "closed by peer: {}", 0)] #[error("closed by peer: {}", 0)]
ApplicationClosed(frame::ApplicationClose), ApplicationClosed(frame::ApplicationClose),
/// The peer is unable to continue processing this connection, usually due to having restarted. /// The peer is unable to continue processing this connection, usually due to having restarted.
#[error(display = "reset by peer")] #[error("reset by peer")]
Reset, Reset,
/// The peer has become unreachable. /// The peer has become unreachable.
#[error(display = "timed out")] #[error("timed out")]
TimedOut, TimedOut,
/// The local application closed the connection. /// The local application closed the connection.
#[error(display = "closed")] #[error("closed")]
LocallyClosed, LocallyClosed,
} }
@@ -3055,12 +3055,6 @@ impl From<ConnectionError> for io::Error {
} }
} }
impl From<transport_parameters::Error> for ConnectionError {
fn from(e: transport_parameters::Error) -> Self {
TransportError::from(e).into()
}
}
#[derive(Clone)] #[derive(Clone)]
enum State { enum State {
Handshake(state::Handshake), Handshake(state::Handshake),
@@ -3223,16 +3217,16 @@ const MIN_PACKET_SPACE: usize = 40;
#[derive(Debug, Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum SendDatagramError { pub enum SendDatagramError {
/// The peer does not support receiving datagram frames /// The peer does not support receiving datagram frames
#[error(display = "datagrams not supported by peer")] #[error("datagrams not supported by peer")]
UnsupportedByPeer, UnsupportedByPeer,
/// Datagram support is disabled locally /// Datagram support is disabled locally
#[error(display = "datagram support disabled")] #[error("datagram support disabled")]
Disabled, Disabled,
/// The datagram is larger than the connection can currently accommodate /// The datagram is larger than the connection can currently accommodate
/// ///
/// Indicates that the path MTU minus overhead or the limit advertised by the peer has been /// Indicates that the path MTU minus overhead or the limit advertised by the peer has been
/// exceeded. /// exceeded.
#[error(display = "datagram too large")] #[error("datagram too large")]
TooLarge, TooLarge,
} }
+10 -10
View File
@@ -4,7 +4,7 @@ use std::{
}; };
use bytes::{BufMut, Bytes}; use bytes::{BufMut, Bytes};
use err_derive::Error; use thiserror::Error;
use tracing::{debug, trace}; use tracing::{debug, trace};
use super::{ use super::{
@@ -922,7 +922,7 @@ pub enum WriteError {
/// be generated, indicating that retrying the write might succeed. /// be generated, indicating that retrying the write might succeed.
/// ///
/// [`StreamEvent::Writable`]: crate::StreamEvent::Writable /// [`StreamEvent::Writable`]: crate::StreamEvent::Writable
#[error(display = "unable to accept further writes")] #[error("unable to accept further writes")]
Blocked, Blocked,
/// The peer is no longer accepting data on this stream, and it has been implicitly reset. The /// The peer is no longer accepting data on this stream, and it has been implicitly reset. The
/// stream cannot be finished or further written to. /// stream cannot be finished or further written to.
@@ -930,13 +930,13 @@ pub enum WriteError {
/// Carries an application-defined error code. /// Carries an application-defined error code.
/// ///
/// [`StreamEvent::Finished`]: crate::StreamEvent::Finished /// [`StreamEvent::Finished`]: crate::StreamEvent::Finished
#[error(display = "stopped by peer: code {}", 0)] #[error("stopped by peer: code {}", 0)]
Stopped(VarInt), Stopped(VarInt),
/// Unknown stream /// Unknown stream
/// ///
/// Occurs when attempting to access a stream after finishing it or observing that it has been /// Occurs when attempting to access a stream after finishing it or observing that it has been
/// stopped. /// stopped.
#[error(display = "unknown stream")] #[error("unknown stream")]
UnknownStream, UnknownStream,
} }
@@ -1081,24 +1081,24 @@ pub enum ReadError {
/// ///
/// If more data on this stream is received from the peer, an `Event::StreamReadable` will be /// If more data on this stream is received from the peer, an `Event::StreamReadable` will be
/// generated for this stream, indicating that retrying the read might succeed. /// generated for this stream, indicating that retrying the read might succeed.
#[error(display = "blocked")] #[error("blocked")]
Blocked, Blocked,
/// The peer abandoned transmitting data on this stream. /// The peer abandoned transmitting data on this stream.
/// ///
/// Carries an application-defined error code. /// Carries an application-defined error code.
#[error(display = "reset by peer: code {}", 0)] #[error("reset by peer: code {}", 0)]
Reset(VarInt), Reset(VarInt),
/// Unknown stream /// Unknown stream
/// ///
/// Occurs when attempting to access a stream after stopping it, or observing that it has been /// Occurs when attempting to access a stream after stopping it, or observing that it has been
/// finished or reset. /// finished or reset.
#[error(display = "unknown stream")] #[error("unknown stream")]
UnknownStream, UnknownStream,
/// Attempted an ordered read following an unordered read /// Attempted an ordered read following an unordered read
/// ///
/// Performing an unordered read allows discontinuities to arise in the receive buffer of a /// Performing an unordered read allows discontinuities to arise in the receive buffer of a
/// stream which cannot be recovered, making further ordered reads impossible. /// stream which cannot be recovered, making further ordered reads impossible.
#[error(display = "ordered read after unordered read")] #[error("ordered read after unordered read")]
IllegalOrderedRead, IllegalOrderedRead,
} }
@@ -1144,10 +1144,10 @@ pub enum FinishError {
/// Carries an application-defined error code. /// Carries an application-defined error code.
/// ///
/// [`StreamEvent::Finished`]: crate::StreamEvent::Finished /// [`StreamEvent::Finished`]: crate::StreamEvent::Finished
#[error(display = "stopped by peer: code {}", 0)] #[error("stopped by peer: code {}", 0)]
Stopped(VarInt), Stopped(VarInt),
/// The stream has not yet been created or was already finished or stopped. /// The stream has not yet been created or was already finished or stopped.
#[error(display = "unknown stream")] #[error("unknown stream")]
UnknownStream, UnknownStream,
} }
+5 -5
View File
@@ -9,9 +9,9 @@ use std::{
}; };
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use err_derive::Error;
use rand::{rngs::StdRng, Rng, RngCore, SeedableRng}; use rand::{rngs::StdRng, Rng, RngCore, SeedableRng};
use slab::Slab; use slab::Slab;
use thiserror::Error;
use tracing::{debug, trace, warn}; use tracing::{debug, trace, warn};
use crate::{ use crate::{
@@ -807,18 +807,18 @@ pub enum ConnectError {
/// The endpoint can no longer create new connections /// The endpoint can no longer create new connections
/// ///
/// Indicates that a necessary component of the endpoint has been dropped or otherwise disabled. /// Indicates that a necessary component of the endpoint has been dropped or otherwise disabled.
#[error(display = "endpoint stopping")] #[error("endpoint stopping")]
EndpointStopping, EndpointStopping,
/// The number of active connections on the local endpoint is at the limit /// The number of active connections on the local endpoint is at the limit
/// ///
/// Try using longer connection IDs. /// Try using longer connection IDs.
#[error(display = "too many connections")] #[error("too many connections")]
TooManyConnections, TooManyConnections,
/// The domain name supplied was malformed /// The domain name supplied was malformed
#[error(display = "invalid DNS name: {}", _0)] #[error("invalid DNS name: {0}")]
InvalidDnsName(String), InvalidDnsName(String),
/// The transport configuration was invalid /// The transport configuration was invalid
#[error(display = "transport configuration error: {}", _0)] #[error("transport configuration error: {0}")]
Config(#[source] ConfigError), Config(#[source] ConfigError),
} }
+3 -3
View File
@@ -1,7 +1,7 @@
use std::{cmp::Ordering, io, ops::Range, str}; use std::{cmp::Ordering, io, ops::Range, str};
use bytes::{Buf, BufMut, Bytes, BytesMut}; use bytes::{Buf, BufMut, Bytes, BytesMut};
use err_derive::Error; use thiserror::Error;
use crate::{ use crate::{
coding::{self, BufExt, BufMutExt}, coding::{self, BufExt, BufMutExt},
@@ -711,13 +711,13 @@ pub(crate) enum LongType {
#[derive(Debug, Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub(crate) enum PacketDecodeError { pub(crate) enum PacketDecodeError {
#[error(display = "unsupported version {:x}", version)] #[error("unsupported version {version:x}")]
UnsupportedVersion { UnsupportedVersion {
src_cid: ConnectionId, src_cid: ConnectionId,
dst_cid: ConnectionId, dst_cid: ConnectionId,
version: u32, version: u32,
}, },
#[error(display = "invalid header: {}", _0)] #[error("invalid header: {0}")]
InvalidHeader(&'static str), InvalidHeader(&'static str),
} }
+3 -3
View File
@@ -12,7 +12,7 @@ use std::{
}; };
use bytes::{buf::ext::BufExt as _, Buf, BufMut}; use bytes::{buf::ext::BufExt as _, Buf, BufMut};
use err_derive::Error; use thiserror::Error;
use crate::{ use crate::{
cid_generator::ConnectionIdGenerator, cid_generator::ConnectionIdGenerator,
@@ -246,10 +246,10 @@ impl PreferredAddress {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Error)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Error)]
pub enum Error { pub enum Error {
/// Parameters that are semantically invalid /// Parameters that are semantically invalid
#[error(display = "parameter had illegal value")] #[error("parameter had illegal value")]
IllegalValue, IllegalValue,
/// Catch-all error for problems while decoding transport parameters /// Catch-all error for problems while decoding transport parameters
#[error(display = "parameters were malformed")] #[error("parameters were malformed")]
Malformed, Malformed,
} }
+2 -2
View File
@@ -1,7 +1,7 @@
use std::{convert::TryInto, fmt}; use std::{convert::TryInto, fmt};
use bytes::{Buf, BufMut}; use bytes::{Buf, BufMut};
use err_derive::Error; use thiserror::Error;
use crate::coding::{self, Codec, UnexpectedEnd}; use crate::coding::{self, Codec, UnexpectedEnd};
@@ -141,7 +141,7 @@ impl Arbitrary for VarInt {
/// Error returned when constructing a `VarInt` from a value >= 2^62 /// Error returned when constructing a `VarInt` from a value >= 2^62
#[derive(Debug, Copy, Clone, Eq, PartialEq, Error)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Error)]
#[error(display = "value too large for varint encoding")] #[error("value too large for varint encoding")]
pub struct VarIntBoundsExceeded; pub struct VarIntBoundsExceeded;
impl Codec for VarInt { impl Codec for VarInt {
+1 -1
View File
@@ -28,12 +28,12 @@ maintenance = { status = "experimental" }
[dependencies] [dependencies]
bytes = "0.5.2" bytes = "0.5.2"
err-derive = "0.2.3"
futures = "0.3.1" futures = "0.3.1"
libc = "0.2.69" libc = "0.2.69"
mio = "0.6" mio = "0.6"
proto = { package = "quinn-proto", path = "../quinn-proto", version = "0.6.1" } proto = { package = "quinn-proto", path = "../quinn-proto", version = "0.6.1" }
rustls = { git = "https://github.com/ctz/rustls", rev = "fee894f7e030", features = ["quic"], optional = true } rustls = { git = "https://github.com/ctz/rustls", rev = "fee894f7e030", features = ["quic"], optional = true }
thiserror = "1.0.21"
tracing = "0.1.10" tracing = "0.1.10"
tokio = { version = "0.2.6", features = ["rt-core", "io-driver", "time"] } tokio = { version = "0.2.6", features = ["rt-core", "io-driver", "time"] }
webpki = { version = "0.21", optional = true } webpki = { version = "0.21", optional = true }
+3 -3
View File
@@ -1,7 +1,7 @@
use std::{io, net::SocketAddr, str, sync::Arc}; use std::{io, net::SocketAddr, sync::Arc};
use err_derive::Error;
use proto::generic::{ClientConfig, EndpointConfig, ServerConfig}; use proto::generic::{ClientConfig, EndpointConfig, ServerConfig};
use thiserror::Error;
use tracing::error; use tracing::error;
use crate::{ use crate::{
@@ -119,7 +119,7 @@ where
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum EndpointError { pub enum EndpointError {
/// An error during setup of the underlying UDP socket. /// An error during setup of the underlying UDP socket.
#[error(display = "failed to set up UDP socket: {}", _0)] #[error("failed to set up UDP socket: {0}")]
Socket(io::Error), Socket(io::Error),
} }
+5 -5
View File
@@ -11,12 +11,12 @@ use std::{
}; };
use bytes::Bytes; use bytes::Bytes;
use err_derive::Error;
use futures::{ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
FutureExt, StreamExt, FutureExt, StreamExt,
}; };
use proto::{ConnectionError, ConnectionHandle, Dir, StreamEvent, StreamId}; use proto::{ConnectionError, ConnectionHandle, Dir, StreamEvent, StreamId};
use thiserror::Error;
use tokio::time::{delay_until, Delay, Instant as TokioInstant}; use tokio::time::{delay_until, Delay, Instant as TokioInstant};
use tracing::info_span; use tracing::info_span;
@@ -984,18 +984,18 @@ where
#[derive(Debug, Error, Clone, Eq, PartialEq)] #[derive(Debug, Error, Clone, Eq, PartialEq)]
pub enum SendDatagramError { pub enum SendDatagramError {
/// The peer does not support receiving datagram frames /// The peer does not support receiving datagram frames
#[error(display = "datagrams not supported by peer")] #[error("datagrams not supported by peer")]
UnsupportedByPeer, UnsupportedByPeer,
/// Datagram support is disabled locally /// Datagram support is disabled locally
#[error(display = "datagram support disabled")] #[error("datagram support disabled")]
Disabled, Disabled,
/// The datagram is larger than the connection can currently accommodate /// The datagram is larger than the connection can currently accommodate
/// ///
/// Indicates that the path MTU minus overhead or the limit advertised by the peer has been /// Indicates that the path MTU minus overhead or the limit advertised by the peer has been
/// exceeded. /// exceeded.
#[error(display = "datagram too large")] #[error("datagram too large")]
TooLarge, TooLarge,
/// The connection was closed /// The connection was closed
#[error(display = "connection closed: {}", _0)] #[error("connection closed: {0}")]
ConnectionClosed(ConnectionError), ConnectionClosed(ConnectionError),
} }
+18 -25
View File
@@ -3,18 +3,17 @@ use std::{
io, io,
mem::MaybeUninit, mem::MaybeUninit,
pin::Pin, pin::Pin,
str,
task::{Context, Poll}, task::{Context, Poll},
}; };
use bytes::Bytes; use bytes::Bytes;
use err_derive::Error;
use futures::{ use futures::{
channel::oneshot, channel::oneshot,
io::{AsyncRead, AsyncWrite}, io::{AsyncRead, AsyncWrite},
ready, FutureExt, ready, FutureExt,
}; };
use proto::{ConnectionError, FinishError, StreamId}; use proto::{ConnectionError, FinishError, StreamId};
use thiserror::Error;
use crate::{connection::ConnectionRef, VarInt}; use crate::{connection::ConnectionRef, VarInt};
@@ -536,19 +535,13 @@ where
#[derive(Debug, Error, Clone, PartialEq, Eq)] #[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum ReadToEndError { pub enum ReadToEndError {
/// An error occurred during reading /// An error occurred during reading
#[error(display = "read error: {}", 0)] #[error("read error: {0}")]
Read(ReadError), Read(#[from] ReadError),
/// The stream is larger than the user-supplied limit /// The stream is larger than the user-supplied limit
#[error(display = "stream too long")] #[error("stream too long")]
TooLong, TooLong,
} }
impl From<ReadError> for ReadToEndError {
fn from(x: ReadError) -> Self {
ReadToEndError::Read(x)
}
}
impl<S> AsyncRead for RecvStream<S> impl<S> AsyncRead for RecvStream<S>
where where
S: proto::crypto::Session, S: proto::crypto::Session,
@@ -607,19 +600,19 @@ pub enum ReadError {
/// The peer abandoned transmitting data on this stream. /// The peer abandoned transmitting data on this stream.
/// ///
/// Carries an application-defined error code. /// Carries an application-defined error code.
#[error(display = "stream reset by peer: error {}", 0)] #[error("stream reset by peer: error {0}")]
Reset(VarInt), Reset(VarInt),
/// The connection was closed. /// The connection was closed.
#[error(display = "connection closed: {}", _0)] #[error("connection closed: {0}")]
ConnectionClosed(ConnectionError), ConnectionClosed(ConnectionError),
/// Unknown stream /// Unknown stream
#[error(display = "unknown stream")] #[error("unknown stream")]
UnknownStream, UnknownStream,
/// Attempted an ordered read following an unordered read /// Attempted an ordered read following an unordered read
/// ///
/// Performing an unordered read allows discontinuities to arise in the receive buffer of a /// Performing an unordered read allows discontinuities to arise in the receive buffer of a
/// stream which cannot be recovered, making further ordered reads impossible. /// stream which cannot be recovered, making further ordered reads impossible.
#[error(display = "ordered read after unordered read")] #[error("ordered read after unordered read")]
IllegalOrderedRead, IllegalOrderedRead,
/// This was a 0-RTT stream and the server rejected it. /// This was a 0-RTT stream and the server rejected it.
/// ///
@@ -627,7 +620,7 @@ pub enum ReadError {
/// [`Connecting::into_0rtt()`]. /// [`Connecting::into_0rtt()`].
/// ///
/// [`Connecting::into_0rtt()`]: crate::generic::Connecting::into_0rtt() /// [`Connecting::into_0rtt()`]: crate::generic::Connecting::into_0rtt()
#[error(display = "0-RTT rejected")] #[error("0-RTT rejected")]
ZeroRttRejected, ZeroRttRejected,
} }
@@ -652,13 +645,13 @@ pub enum WriteError {
/// The peer is no longer accepting data on this stream. /// The peer is no longer accepting data on this stream.
/// ///
/// Carries an application-defined error code. /// Carries an application-defined error code.
#[error(display = "sending stopped by peer: error {}", 0)] #[error("sending stopped by peer: error {0}")]
Stopped(VarInt), Stopped(VarInt),
/// The connection was closed. /// The connection was closed.
#[error(display = "connection closed: {}", _0)] #[error("connection closed: {0}")]
ConnectionClosed(ConnectionError), ConnectionClosed(ConnectionError),
/// Unknown stream /// Unknown stream
#[error(display = "unknown stream")] #[error("unknown stream")]
UnknownStream, UnknownStream,
/// This was a 0-RTT stream and the server rejected it. /// This was a 0-RTT stream and the server rejected it.
/// ///
@@ -666,7 +659,7 @@ pub enum WriteError {
/// [`Connecting::into_0rtt()`]. /// [`Connecting::into_0rtt()`].
/// ///
/// [`Connecting::into_0rtt()`]: crate::generic::Connecting::into_0rtt() /// [`Connecting::into_0rtt()`]: crate::generic::Connecting::into_0rtt()
#[error(display = "0-RTT rejected")] #[error("0-RTT rejected")]
ZeroRttRejected, ZeroRttRejected,
} }
@@ -674,10 +667,10 @@ pub enum WriteError {
#[derive(Debug, Error, Clone, PartialEq, Eq)] #[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum StoppedError { pub enum StoppedError {
/// The connection was closed. /// The connection was closed.
#[error(display = "connection closed: {}", _0)] #[error("connection closed: {0}")]
ConnectionClosed(ConnectionError), ConnectionClosed(ConnectionError),
/// Unknown stream /// Unknown stream
#[error(display = "unknown stream")] #[error("unknown stream")]
UnknownStream, UnknownStream,
/// This was a 0-RTT stream and the server rejected it. /// This was a 0-RTT stream and the server rejected it.
/// ///
@@ -685,7 +678,7 @@ pub enum StoppedError {
/// [`Connecting::into_0rtt()`]. /// [`Connecting::into_0rtt()`].
/// ///
/// [`Connecting::into_0rtt()`]: crate::generic::Connecting::into_0rtt() /// [`Connecting::into_0rtt()`]: crate::generic::Connecting::into_0rtt()
#[error(display = "0-RTT rejected")] #[error("0-RTT rejected")]
ZeroRttRejected, ZeroRttRejected,
} }
@@ -760,10 +753,10 @@ where
#[derive(Debug, Error, Clone, PartialEq, Eq)] #[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum ReadExactError { pub enum ReadExactError {
/// The stream finished before all bytes were read /// The stream finished before all bytes were read
#[error(display = "stream finished early")] #[error("stream finished early")]
FinishedEarly, FinishedEarly,
/// A read error occurred /// A read error occurred
#[error(display = "{}", 0)] #[error("{0}")]
ReadError(ReadError), ReadError(ReadError),
} }