diff --git a/dc/s2n-quic-dc/src/stream/recv/error.rs b/dc/s2n-quic-dc/src/stream/recv/error.rs index e5cb85ac72..d38c2511a7 100644 --- a/dc/s2n-quic-dc/src/stream/recv/error.rs +++ b/dc/s2n-quic-dc/src/stream/recv/error.rs @@ -37,7 +37,7 @@ impl fmt::Display for Error { } } -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl IntoEvent for Error { fn into_event(self) -> Error { diff --git a/dc/s2n-quic-dc/src/stream/send/error.rs b/dc/s2n-quic-dc/src/stream/send/error.rs index eeb34c3f81..9da543d541 100644 --- a/dc/s2n-quic-dc/src/stream/send/error.rs +++ b/dc/s2n-quic-dc/src/stream/send/error.rs @@ -34,7 +34,7 @@ impl fmt::Display for Error { } } -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl IntoEvent for Error { fn into_event(self) -> Error { diff --git a/quic/s2n-quic-core/events/connection.rs b/quic/s2n-quic-core/events/connection.rs index c0a84e26f8..c5108afed8 100644 --- a/quic/s2n-quic-core/events/connection.rs +++ b/quic/s2n-quic-core/events/connection.rs @@ -345,6 +345,7 @@ struct TlsExporterReady<'a> { #[event("connectivity:tls_handshake_failed")] struct TlsHandshakeFailed<'a> { session: crate::event::TlsSession<'a>, + error: &'a (dyn core::error::Error + Send + Sync + 'static), } #[event("connectivity:path_challenge_updated")] diff --git a/quic/s2n-quic-core/src/application/error.rs b/quic/s2n-quic-core/src/application/error.rs index 3a46554e52..ebd2ef1cf0 100644 --- a/quic/s2n-quic-core/src/application/error.rs +++ b/quic/s2n-quic-core/src/application/error.rs @@ -18,8 +18,7 @@ use core::{fmt, ops}; #[derive(Copy, Clone, Eq, PartialEq)] pub struct Error(VarInt); -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/quic/s2n-quic-core/src/buffer/deque.rs b/quic/s2n-quic-core/src/buffer/deque.rs index 10f23cccea..2e78f2c09f 100644 --- a/quic/s2n-quic-core/src/buffer/deque.rs +++ b/quic/s2n-quic-core/src/buffer/deque.rs @@ -225,8 +225,7 @@ impl fmt::Display for FillError { } } -#[cfg(feature = "std")] -impl std::error::Error for FillError {} +impl core::error::Error for FillError {} #[cfg(feature = "std")] impl From for std::io::Error { diff --git a/quic/s2n-quic-core/src/connection/error.rs b/quic/s2n-quic-core/src/connection/error.rs index c2746bcb7c..b99a44c045 100644 --- a/quic/s2n-quic-core/src/connection/error.rs +++ b/quic/s2n-quic-core/src/connection/error.rs @@ -101,8 +101,7 @@ pub enum Error { }, } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/quic/s2n-quic-core/src/crypto/tls.rs b/quic/s2n-quic-core/src/crypto/tls.rs index 6a5b916fce..01c8424099 100644 --- a/quic/s2n-quic-core/src/crypto/tls.rs +++ b/quic/s2n-quic-core/src/crypto/tls.rs @@ -166,6 +166,7 @@ pub trait Context { fn on_tls_handshake_failed( &mut self, session: &impl TlsSession, + error: &(dyn core::error::Error + Send + Sync + 'static), ) -> Result<(), crate::transport::Error>; /// Receives data from the initial packet space diff --git a/quic/s2n-quic-core/src/crypto/tls/offload.rs b/quic/s2n-quic-core/src/crypto/tls/offload.rs index 21106e0587..a0edac5a64 100644 --- a/quic/s2n-quic-core/src/crypto/tls/offload.rs +++ b/quic/s2n-quic-core/src/crypto/tls/offload.rs @@ -21,7 +21,11 @@ pub trait Executor { /// Allows access to the TlsSession on handshake failure and when the exporter secret is ready. pub trait ExporterHandler { - fn on_tls_handshake_failed(&self, session: &impl TlsSession) -> Option>; + fn on_tls_handshake_failed( + &self, + session: &impl TlsSession, + e: &(dyn core::error::Error + Send + Sync + 'static), + ) -> Option>; fn on_tls_exporter_ready(&self, session: &impl TlsSession) -> Option>; } @@ -30,6 +34,7 @@ impl ExporterHandler for () { fn on_tls_handshake_failed( &self, _session: &impl TlsSession, + _e: &(dyn core::error::Error + Send + Sync + 'static), ) -> Option> { None } @@ -559,8 +564,9 @@ impl tls::Context for RemoteContext<'_, R fn on_tls_handshake_failed( &mut self, session: &impl tls::TlsSession, + e: &(dyn core::error::Error + Send + Sync + 'static), ) -> Result<(), crate::transport::Error> { - if let Some(context) = self.exporter_handler.on_tls_handshake_failed(session) { + if let Some(context) = self.exporter_handler.on_tls_handshake_failed(session, e) { match self.send_to_quic.push(Request::TlsContext(context)) { Ok(_) => (), Err(_) => self.error = Some(SLICE_ERROR), diff --git a/quic/s2n-quic-core/src/crypto/tls/slow_tls.rs b/quic/s2n-quic-core/src/crypto/tls/slow_tls.rs index 7beebf1bce..dfc33bb4a2 100644 --- a/quic/s2n-quic-core/src/crypto/tls/slow_tls.rs +++ b/quic/s2n-quic-core/src/crypto/tls/slow_tls.rs @@ -167,8 +167,9 @@ where fn on_tls_handshake_failed( &mut self, session: &impl tls::TlsSession, + e: &(dyn core::error::Error + Send + Sync + 'static), ) -> Result<(), transport::Error> { - self.0.on_tls_exporter_ready(session) + self.0.on_tls_handshake_failed(session, e) } fn receive_initial(&mut self, max_len: Option) -> Option { diff --git a/quic/s2n-quic-core/src/crypto/tls/testing.rs b/quic/s2n-quic-core/src/crypto/tls/testing.rs index 4df2634215..d24a6713bc 100644 --- a/quic/s2n-quic-core/src/crypto/tls/testing.rs +++ b/quic/s2n-quic-core/src/crypto/tls/testing.rs @@ -779,6 +779,7 @@ where fn on_tls_handshake_failed( &mut self, _: &impl super::TlsSession, + _: &(dyn std::error::Error + Send + Sync), ) -> Result<(), crate::transport::Error> { Ok(()) } diff --git a/quic/s2n-quic-core/src/datagram/default.rs b/quic/s2n-quic-core/src/datagram/default.rs index 8f2a95d67b..91ebd3799d 100644 --- a/quic/s2n-quic-core/src/datagram/default.rs +++ b/quic/s2n-quic-core/src/datagram/default.rs @@ -49,8 +49,7 @@ pub enum BuilderError { ZeroCapacity, } -#[cfg(feature = "std")] -impl std::error::Error for BuilderError {} +impl core::error::Error for BuilderError {} impl fmt::Display for BuilderError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/quic/s2n-quic-core/src/event.rs b/quic/s2n-quic-core/src/event.rs index 5151a7ccf6..85ca93d504 100644 --- a/quic/s2n-quic-core/src/event.rs +++ b/quic/s2n-quic-core/src/event.rs @@ -66,7 +66,14 @@ ident_into_event!( connection::Error, endpoint::Location, ); -borrowed_into_event!([u8; 4], [u8; 16], [u8], [u32], [&'a [u8]]); +borrowed_into_event!( + [u8; 4], + [u8; 16], + [u8], + [u32], + [&'a [u8]], + (dyn core::error::Error + Send + Sync + 'static) +); impl, U> IntoEvent> for Option { #[inline] diff --git a/quic/s2n-quic-core/src/event/generated.rs b/quic/s2n-quic-core/src/event/generated.rs index ead9b37843..d1be09194c 100644 --- a/quic/s2n-quic-core/src/event/generated.rs +++ b/quic/s2n-quic-core/src/event/generated.rs @@ -2468,12 +2468,14 @@ pub mod api { #[non_exhaustive] pub struct TlsHandshakeFailed<'a> { pub session: crate::event::TlsSession<'a>, + pub error: &'a (dyn core::error::Error + Send + Sync + 'static), } #[cfg(any(test, feature = "testing"))] impl<'a> crate::event::snapshot::Fmt for TlsHandshakeFailed<'a> { fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { let mut fmt = fmt.debug_struct("TlsHandshakeFailed"); fmt.field("session", &self.session); + fmt.field("error", &self.error); fmt.finish() } } @@ -4132,8 +4134,8 @@ pub mod tracing { event: &api::TlsHandshakeFailed, ) { let id = context.id(); - let api::TlsHandshakeFailed { session } = event; - tracing :: event ! (target : "tls_handshake_failed" , parent : id , tracing :: Level :: DEBUG , { session = tracing :: field :: debug (session) }); + let api::TlsHandshakeFailed { session, error } = event; + tracing :: event ! (target : "tls_handshake_failed" , parent : id , tracing :: Level :: DEBUG , { session = tracing :: field :: debug (session) , error = tracing :: field :: debug (error) }); } #[inline] fn on_path_challenge_updated( @@ -6300,13 +6302,15 @@ pub mod builder { #[derive(Clone, Debug)] pub struct TlsHandshakeFailed<'a> { pub session: crate::event::TlsSession<'a>, + pub error: &'a (dyn core::error::Error + Send + Sync + 'static), } impl<'a> IntoEvent> for TlsHandshakeFailed<'a> { #[inline] fn into_event(self) -> api::TlsHandshakeFailed<'a> { - let TlsHandshakeFailed { session } = self; + let TlsHandshakeFailed { session, error } = self; api::TlsHandshakeFailed { session: session.into_event(), + error: error.into_event(), } } } diff --git a/quic/s2n-quic-core/src/path/mtu.rs b/quic/s2n-quic-core/src/path/mtu.rs index ee17b3a447..52c084cdc1 100644 --- a/quic/s2n-quic-core/src/path/mtu.rs +++ b/quic/s2n-quic-core/src/path/mtu.rs @@ -241,8 +241,7 @@ impl Display for MtuError { } } -#[cfg(feature = "std")] -impl std::error::Error for MtuError {} +impl core::error::Error for MtuError {} /// Information about the path that may be used when generating MTU configuration. #[non_exhaustive] diff --git a/quic/s2n-quic-core/src/query.rs b/quic/s2n-quic-core/src/query.rs index 562caf4748..3e8a8f5066 100644 --- a/quic/s2n-quic-core/src/query.rs +++ b/quic/s2n-quic-core/src/query.rs @@ -132,5 +132,4 @@ impl core::fmt::Display for Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} diff --git a/quic/s2n-quic-core/src/stream/error.rs b/quic/s2n-quic-core/src/stream/error.rs index 36fb4a9c09..ab83c5a3f0 100644 --- a/quic/s2n-quic-core/src/stream/error.rs +++ b/quic/s2n-quic-core/src/stream/error.rs @@ -68,8 +68,7 @@ pub enum StreamError { }, } -#[cfg(feature = "std")] -impl std::error::Error for StreamError {} +impl core::error::Error for StreamError {} impl fmt::Display for StreamError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/quic/s2n-quic-core/src/transport/error.rs b/quic/s2n-quic-core/src/transport/error.rs index 815d49f591..2b41e9d23c 100644 --- a/quic/s2n-quic-core/src/transport/error.rs +++ b/quic/s2n-quic-core/src/transport/error.rs @@ -29,8 +29,7 @@ pub struct Error { pub reason: &'static str, } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl Error { /// Creates a new `Error` diff --git a/quic/s2n-quic-core/src/transport/parameters/mod.rs b/quic/s2n-quic-core/src/transport/parameters/mod.rs index c3ae4764af..49d97dcc24 100644 --- a/quic/s2n-quic-core/src/transport/parameters/mod.rs +++ b/quic/s2n-quic-core/src/transport/parameters/mod.rs @@ -259,8 +259,7 @@ impl From for ValidationError { } } -#[cfg(feature = "std")] -impl std::error::Error for ValidationError {} +impl core::error::Error for ValidationError {} /// Creates a transport parameter struct with the inner codec type macro_rules! transport_parameter { diff --git a/quic/s2n-quic-core/src/varint/mod.rs b/quic/s2n-quic-core/src/varint/mod.rs index d99b611f3d..6279191d91 100644 --- a/quic/s2n-quic-core/src/varint/mod.rs +++ b/quic/s2n-quic-core/src/varint/mod.rs @@ -34,8 +34,7 @@ impl fmt::Display for VarIntError { } } -#[cfg(feature = "std")] -impl std::error::Error for VarIntError {} +impl core::error::Error for VarIntError {} // === API === diff --git a/quic/s2n-quic-rustls/src/session.rs b/quic/s2n-quic-rustls/src/session.rs index 32fd4558b6..9540f00528 100644 --- a/quic/s2n-quic-rustls/src/session.rs +++ b/quic/s2n-quic-rustls/src/session.rs @@ -381,8 +381,8 @@ impl tls::Session for Session { context: &mut C, ) -> Poll> { let result = self.poll_impl(context); - if let Poll::Ready(Err(_)) = &result { - context.on_tls_handshake_failed(self)?; + if let Poll::Ready(Err(e)) = &result { + context.on_tls_handshake_failed(self, e)?; } // attempt to emit server_name and application_protocol events prior to possibly // returning with an error diff --git a/quic/s2n-quic-tests/src/tests/offload.rs b/quic/s2n-quic-tests/src/tests/offload.rs index a2a7a699c3..6001f78442 100644 --- a/quic/s2n-quic-tests/src/tests/offload.rs +++ b/quic/s2n-quic-tests/src/tests/offload.rs @@ -18,6 +18,7 @@ impl ExporterHandler for Exporter { fn on_tls_handshake_failed( &self, _session: &impl s2n_quic_core::crypto::tls::TlsSession, + _e: &(dyn core::error::Error + Send + Sync + 'static), ) -> Option> { None } diff --git a/quic/s2n-quic-tls/src/session.rs b/quic/s2n-quic-tls/src/session.rs index 7ae40c6651..44ba29d7af 100644 --- a/quic/s2n-quic-tls/src/session.rs +++ b/quic/s2n-quic-tls/src/session.rs @@ -162,7 +162,7 @@ impl tls::Session for Session { Poll::Ready(Ok(())) } Poll::Ready(Err(e)) => { - context.on_tls_handshake_failed(self)?; + context.on_tls_handshake_failed(self, &e)?; Poll::Ready(Err(e .alert() diff --git a/quic/s2n-quic-transport/src/space/session_context.rs b/quic/s2n-quic-transport/src/space/session_context.rs index 747bf9724d..cfd84aeff7 100644 --- a/quic/s2n-quic-transport/src/space/session_context.rs +++ b/quic/s2n-quic-transport/src/space/session_context.rs @@ -570,10 +570,12 @@ impl fn on_tls_handshake_failed( &mut self, session: &impl tls::TlsSession, + e: &(dyn std::error::Error + Send + Sync + 'static), ) -> Result<(), transport::Error> { self.publisher .on_tls_handshake_failed(event::builder::TlsHandshakeFailed { session: s2n_quic_core::event::TlsSession::new(session), + error: e, }); Ok(()) } diff --git a/quic/s2n-quic/src/provider.rs b/quic/s2n-quic/src/provider.rs index 91a34c4e6e..94edd856f8 100644 --- a/quic/s2n-quic/src/provider.rs +++ b/quic/s2n-quic/src/provider.rs @@ -77,7 +77,7 @@ cfg_if!( /// An error indicating a failure to start an endpoint pub struct StartError(Box); -impl std::error::Error for StartError {} +impl core::error::Error for StartError {} impl StartError { pub(crate) fn new(error: T) -> Self {