diff --git a/h3/src/connection.rs b/h3/src/connection.rs index 4064373d..49f0eb8c 100644 --- a/h3/src/connection.rs +++ b/h3/src/connection.rs @@ -346,7 +346,7 @@ where } #[allow(missing_docs)] - //#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))] + #[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))] pub fn poll_accept_bi( &mut self, cx: &mut Context<'_>, @@ -495,7 +495,7 @@ where } /// Waits for the control stream to be received and reads subsequent frames. - //#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))] + #[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))] pub fn poll_control( &mut self, cx: &mut Context<'_>, @@ -657,7 +657,7 @@ where &mut self, recv_closing: &mut Option, id: VarInt, - ) -> Result<(), Error> + ) -> Result<(), ConnectionError> where T: From + Copy, VarInt: From, @@ -678,13 +678,12 @@ where //= https://www.rfc-editor.org/rfc/rfc9114#section-5.2 //# Receiving a GOAWAY containing a larger identifier than previously //# received MUST be treated as a connection error of type H3_ID_ERROR. - return Err(self.close( - Code::H3_ID_ERROR, - format!( - "received a GoAway({}) greater than the former one ({})", - id, prev_id - ), - )); + return Err(self.handle_connection_error(InternalConnectionError::new( + NewCode::H3_ID_ERROR, + // TODO: put the id in the message + //received a GoAway({}) greater than the former one ({})", + "received a GoAway greater than the former one", + ))); } } *recv_closing = Some(id.into()); @@ -843,7 +842,7 @@ impl ConnectionState for RequestStream { impl RequestStream { /// Close the connection with an error - //#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))] + #[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))] pub fn close(&self, code: Code, reason: &'static str) -> Error { let _ = self.error_sender.send((code, reason)); self.maybe_conn_err(code) diff --git a/h3/src/error.rs b/h3/src/error.rs index bc55d941..08295907 100644 --- a/h3/src/error.rs +++ b/h3/src/error.rs @@ -401,71 +401,12 @@ impl From for Error { } } -impl From for Error { - fn from(e: frame::FrameStreamError) -> Self { - match e { - frame::FrameStreamError::Quic(e) => e.into(), - - //= https://www.rfc-editor.org/rfc/rfc9114#section-7.1 - //# When a stream terminates cleanly, if the last frame on the stream was - //# truncated, this MUST be treated as a connection error of type - //# H3_FRAME_ERROR. - frame::FrameStreamError::UnexpectedEnd => Code::H3_FRAME_ERROR - .with_reason("received incomplete frame", ErrorLevel::ConnectionError), - - frame::FrameStreamError::Proto(e) => match e { - proto::frame::FrameError::InvalidStreamId(_) - | proto::frame::FrameError::InvalidPushId(_) => Code::H3_ID_ERROR, - proto::frame::FrameError::Settings(_) => Code::H3_SETTINGS_ERROR, - proto::frame::FrameError::UnsupportedFrame(_) - | proto::frame::FrameError::UnknownFrame(_) => Code::H3_FRAME_UNEXPECTED, - - //= https://www.rfc-editor.org/rfc/rfc9114#section-7.1 - //# A frame payload that contains additional bytes - //# after the identified fields or a frame payload that terminates before - //# the end of the identified fields MUST be treated as a connection - //# error of type H3_FRAME_ERROR. - - //= https://www.rfc-editor.org/rfc/rfc9114#section-7.1 - //# In particular, redundant length - //# encodings MUST be verified to be self-consistent; see Section 10.8. - proto::frame::FrameError::Incomplete(_) - | proto::frame::FrameError::InvalidFrameValue - | proto::frame::FrameError::Malformed => Code::H3_FRAME_ERROR, - } - .with_cause(e), - } - } -} - impl From for Box { fn from(e: Error) -> Self { Box::new(e) } } -impl From for Error -where - T: Into, -{ - fn from(e: T) -> Self { - let quic_error: TransportError = e.into(); - if quic_error.is_timeout() { - return Error::new(Kind::Timeout); - } - - match quic_error.err_code() { - Some(c) if Code::H3_NO_ERROR == c => Error::new(Kind::Closed), - Some(c) => Error::new(Kind::Application { - code: Code { code: c }, - reason: None, - level: ErrorLevel::ConnectionError, - }), - None => Error::new(Kind::Transport(Arc::from(quic_error))), - } - } -} - impl From for Error { fn from(e: proto::stream::InvalidStreamId) -> Self { Self::from(Code::H3_ID_ERROR).with_cause(format!("{}", e))