Skip to content

Commit

Permalink
some progress with new error types
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2424 committed Jan 11, 2025
1 parent 8832ef5 commit e735ab3
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 9 deletions.
48 changes: 48 additions & 0 deletions h3/src/error2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,54 @@ pub enum StreamError {
ConnectionError(ConnectionError),
}

/// This enum represents a stream error
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ServerStreamError {
/// The error occurred on the stream
#[non_exhaustive]
StreamError {
/// The error code
code: NewCode,
/// The error reason
reason: &'static str,
},
/// The error occurred on the connection
#[non_exhaustive]
ConnectionError(ConnectionError),
#[non_exhaustive]
/// The received header block is too big
/// The Request has been answered with a 431 Request Header Fields Too Large
HeaderTooBig { actual_size: u64, max_size: u64 },
}

impl std::fmt::Display for ServerStreamError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ServerStreamError::StreamError { code, reason } => {
write!(f, "Stream error: {:?} - {}", code, reason)
}
ServerStreamError::ConnectionError(err) => write!(f, "Connection error: {}", err),
ServerStreamError::HeaderTooBig { actual_size, max_size } => write!(
f,
"Header too big: actual size: {}, max size: {}",
actual_size, max_size
),
}
}
}

impl std::error::Error for ServerStreamError {}

impl From<StreamError> for ServerStreamError {
fn from(err: StreamError) -> Self {
match err {
StreamError::StreamError { code, reason } => ServerStreamError::StreamError { code, reason },
StreamError::ConnectionError(err) => ServerStreamError::ConnectionError(err),
}
}
}

impl std::fmt::Display for ConnectionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
19 changes: 18 additions & 1 deletion h3/src/error2/internal_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@ pub enum ErrorScope {
/// to represent errors, which have not yet affected the connection or stream state
///
/// This error type is generated from the error types of h3s submodules or by the modules itself.
///
/// This error type is used in functions which handle a http3 request stream
#[derive(Debug, Clone, Hash)]
pub struct InternalError {
pub struct InternalRequestStreamError {
/// The error scope
scope: ErrorScope,
/// The error code
code: Code,
/// The error message
message: &'static str,
}


/// This error type represents an internal error type, which is used
/// to represent errors, which have not yet affected the connection state
///
/// This error type is generated from the error types of h3s submodules or by the modules itself.
///
/// This error type is used in functions which handle a http3 connection state
#[derive(Debug, Clone, Hash)]
pub struct InternalConnectionError {
/// The error code
code: Code,
/// The error message
message: &'static str,
}
25 changes: 17 additions & 8 deletions h3/src/error2/traits.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
//! Defines error traits
use crate::config::Config;
use crate::{config::Config, shared_state::ConnectionState2};

use super::{internal_error::InternalError, ConnectionError};
use super::{codes::NewCode, internal_error::InternalRequestStreamError, ConnectionError};

/// This trait is implemented for all types which can close the connection
pub(crate) trait CloseConnection {
pub(crate) trait CloseConnection: ConnectionState2 {

Check warning on line 8 in h3/src/error2/traits.rs

View workflow job for this annotation

GitHub Actions / Lint

trait `CloseConnection` is never used
/// Close the connection
fn handle_error(&mut self, internal_error: InternalError) -> ConnectionError {
fn handle_connection_error(
&mut self,
internal_error: InternalRequestStreamError,

Check warning on line 12 in h3/src/error2/traits.rs

View workflow job for this annotation

GitHub Actions / Lint

unused variable: `internal_error`
) -> ConnectionError {

//self.maybe_conn_error(error)
todo!()
}

fn close_connection<T: AsRef<str>>(code: &NewCode, reason: T) -> ();

Check warning on line 19 in h3/src/error2/traits.rs

View workflow job for this annotation

GitHub Actions / Lint

unneeded unit return type
}

pub(crate) trait CloseStream {
fn handle_error(&mut self, internal_error: InternalError, config: &Config) -> ConnectionError {
pub(crate) trait CloseStream: CloseConnection {
fn handle_stream_error(
&mut self,
internal_error: InternalRequestStreamError,

Check warning on line 25 in h3/src/error2/traits.rs

View workflow job for this annotation

GitHub Actions / Lint

unused variable: `internal_error`
config: &Config,

Check warning on line 26 in h3/src/error2/traits.rs

View workflow job for this annotation

GitHub Actions / Lint

unused variable: `config`
) -> ConnectionError {
todo!()
}

fn close_stream() -> ();

Check warning on line 31 in h3/src/error2/traits.rs

View workflow job for this annotation

GitHub Actions / Lint

unneeded unit return type

fn close_connection() -> ();
}

0 comments on commit e735ab3

Please sign in to comment.