1use miette::Diagnostic;
4use std::{net::SocketAddr, time::Duration};
5use thiserror::Error;
6use tokio::io::Error as TokioIOError;
7
8#[derive(Error, Diagnostic, Debug)]
10pub enum CommonNetAPIError {
11 #[error("Failed to lookup host to bind too (TCP): {0:?}")]
12 #[diagnostic(code(cat_dev::net::api::address_lookup_error))]
13 AddressLookupError(#[from] TokioIOError),
14 #[error("You cannot register two fallback handlers on the same router!")]
15 #[diagnostic(code(cat_dev::net::api::cannot_register_two_fallback_handlers))]
16 DuplicateFallbackHandler,
17 #[error("Built-in L4 router does not support multiple handlers on the same route!")]
18 #[diagnostic(code(cat_dev::net::api::duplicate_route))]
19 DuplicateRoute(Vec<u8>),
20 #[error("Failed to find an extension that was requested for a handler!")]
21 #[diagnostic(code(cat_dev::net::api::extension_not_present))]
22 ExtensionNotPresent,
23 #[error("A Nagle guard on an end search cannot be empty!")]
24 #[diagnostic(code(cat_dev::net::api::nagle_guard_end_sigil_cannot_be_empty))]
25 NagleGuardEndSigilCannotBeEmpty,
26 #[error("A stream begin hook or (on connection hook) has already been registered!")]
27 #[diagnostic(code(cat_dev::net::api::stream_begin_hook_already_registered))]
28 OnStreamBeginAlreadyRegistered,
29 #[error(
30 "A stream begin hook or (on connection hook) has not yet been registered! It is needed to layer!"
31 )]
32 #[diagnostic(code(cat_dev::net::api::stream_begin_hook_not_registered))]
33 OnStreamBeginNotRegistered,
34 #[error("A stream end hook or (on disconnect hook) has already been registered!")]
35 #[diagnostic(code(cat_dev::net::api::stream_end_hook_already_registered))]
36 OnStreamEndAlreadyRegistered,
37 #[error(
38 "A stream end hook or (on disconnect hook) has not yet been registered! It is needed to layer!"
39 )]
40 #[diagnostic(code(cat_dev::net::api::stream_begin_end_not_registered))]
41 OnStreamEndNotRegistered,
42 #[error(
43 "The built-in router for our L4 server had `add_route` called without a byte prefix to match on. We need at least one byte!"
44 )]
45 #[diagnostic(code(cat_dev::net::api::router_needs_some_bytes))]
46 RouterNeedsSomeBytesToMatchOn,
47 #[error(
48 "The built-in router for our L4 server had `add_route` called with a series of bytes that are longer than 16 bytes: {0:02x?}, but we can only match on 16 bytes long!"
49 )]
50 #[diagnostic(code(cat_dev::net::api::router_too_long_to_match_on))]
51 RouteTooLongToMatchOn(Vec<u8>),
52 #[error(
53 "Looking up address returned no/multiple address to bind too, but we only know how to bind to a single address: {0:?}"
54 )]
55 #[diagnostic(code(cat_dev::net::api::wrong_amount_of_addresses_to_bind_too))]
56 WrongAmountOfAddressesToBindToo(Vec<SocketAddr>),
57}
58
59#[derive(Error, Diagnostic, Debug, PartialEq, Eq)]
60pub enum CommonNetNetworkError {
61 #[error("A client has taken too long to send us a single packet, it has been: {0:?}")]
63 #[diagnostic(code(cat_dev::net::common_network::slowloris_timeout))]
64 SlowlorisTimeout(Duration),
65 #[error(
67 "internal: A request tried to read more data from it's stream, but the stream is not actively being processed!"
68 )]
69 #[diagnostic(code(cat_dev::net::common_network::stream_no_longer_processing))]
70 StreamNoLongerProcessing,
71}