sim_lib_net_core/error.rs
1//! The NetError type for net-core parsing failures.
2
3/// Errors produced by the net-core parsing primitives.
4///
5/// These describe malformed or oversize wire data only. They carry no I/O or
6/// application context; callers translate them into their own error domain.
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub enum NetError {
9 /// The URL did not contain a `scheme://` separator, or was otherwise
10 /// structurally malformed (e.g. missing host).
11 MalformedUrl(String),
12 /// The URL scheme is not one this crate recognizes for default-port
13 /// resolution.
14 UnsupportedScheme(String),
15 /// The URL scheme did not match the scheme a caller required (via
16 /// [`parse_url_for_scheme`](crate::parse_url_for_scheme)).
17 UnexpectedScheme {
18 /// The scheme the caller required.
19 expected: String,
20 /// The scheme actually found in the URL.
21 found: String,
22 },
23 /// The URL port component could not be parsed as a `u16`.
24 InvalidPort(String),
25 /// The HTTP response head (status line + headers) was malformed.
26 InvalidHead(String),
27 /// A chunked-transfer size line was malformed.
28 InvalidChunkSize(String),
29 /// A chunked-transfer body ended before a complete chunk or trailer section.
30 TruncatedChunk,
31 /// A chunked-transfer chunk or trailer section used the wrong delimiter.
32 InvalidChunkDelimiter,
33 /// A length-prefixed or buffered payload exceeded the caller's size limit.
34 OversizeBody(usize),
35 /// A newline-delimited line exceeded the configured line size limit.
36 LineTooLong {
37 /// Maximum accepted line length in bytes.
38 max: usize,
39 },
40}
41
42impl core::fmt::Display for NetError {
43 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44 match self {
45 Self::MalformedUrl(url) => write!(formatter, "malformed url {url}"),
46 Self::UnsupportedScheme(scheme) => write!(formatter, "unsupported url scheme {scheme}"),
47 Self::UnexpectedScheme { expected, found } => {
48 write!(formatter, "expected url scheme {expected}, found {found}")
49 }
50 Self::InvalidPort(url) => write!(formatter, "invalid port in url {url}"),
51 Self::InvalidHead(detail) => write!(formatter, "invalid http head: {detail}"),
52 Self::InvalidChunkSize(detail) => write!(formatter, "invalid chunk size: {detail}"),
53 Self::TruncatedChunk => write!(formatter, "truncated chunked body"),
54 Self::InvalidChunkDelimiter => write!(formatter, "invalid chunked body delimiter"),
55 Self::OversizeBody(limit) => {
56 write!(formatter, "payload exceeded size limit of {limit} bytes")
57 }
58 Self::LineTooLong { max } => {
59 write!(formatter, "line exceeded size limit of {max} bytes")
60 }
61 }
62 }
63}
64
65impl core::error::Error for NetError {}