Shrink Error type enum to 48 bytes

This commit is contained in:
Mike Dilger 2026-02-21 12:18:50 +13:00
parent a1e52a2d07
commit 1f2c33d532
No known key found for this signature in database
GPG Key ID: 47581A78D4329BA4
2 changed files with 39 additions and 30 deletions

View File

@ -45,7 +45,7 @@ pub enum ChorusError {
BannedUser, BannedUser,
// Base64 Decode Error // Base64 Decode Error
Base64Decode(base64::DecodeError), Base64Decode(base64::DecodeError), // 24b
// Blocked IP // Blocked IP
BlockedIp, BlockedIp,
@ -54,16 +54,16 @@ pub enum ChorusError {
BlossomAuthFailure(String), BlossomAuthFailure(String),
// Channel Recv // Channel Recv
ChannelRecv(tokio::sync::broadcast::error::RecvError), ChannelRecv(tokio::sync::broadcast::error::RecvError), // 24b
// Channel Send // Channel Send
ChannelSend(tokio::sync::broadcast::error::SendError<u64>), ChannelSend(tokio::sync::broadcast::error::SendError<u64>), // 16b
// Config // Config
Config(toml::de::Error), Config(Box<toml::de::Error>), // 16b
// Crypto // Crypto
Crypto(secp256k1::Error), Crypto(secp256k1::Error), // 16b
// Closing on error(s) // Closing on error(s)
ErrorClose, ErrorClose,
@ -72,16 +72,16 @@ pub enum ChorusError {
EventIsInvalid(String), EventIsInvalid(String),
// From hex // From hex
FromHex(hex::FromHexError), FromHex(hex::FromHexError), // 24b
// From UTF8 // From UTF8
FromUtf8(std::string::FromUtf8Error), FromUtf8(Box<std::string::FromUtf8Error>),
// General // General
General(String), General(String),
// Http // Http
Http(hyper::http::Error), Http(Box<hyper::http::Error>),
// Hyper // Hyper
Hyper(hyper::Error), Hyper(hyper::Error),
@ -126,7 +126,7 @@ pub enum ChorusError {
PocketDb(pocket_db::Error), PocketDb(pocket_db::Error),
// Pocket Db Heed Error // Pocket Db Heed Error
PocketDbHeed(pocket_db::heed::Error), PocketDbHeed(Box<pocket_db::heed::Error>),
// Pocket Types Error // Pocket Types Error
PocketType(pocket_types::Error), PocketType(pocket_types::Error),
@ -141,7 +141,7 @@ pub enum ChorusError {
Restricted, Restricted,
// Rustls // Rustls
Rustls(tokio_rustls::rustls::Error), Rustls(Box<tokio_rustls::rustls::Error>),
// Filter is underspecified // Filter is underspecified
Scraper, Scraper,
@ -165,7 +165,7 @@ pub enum ChorusError {
TooManySubscriptions, TooManySubscriptions,
// Tungstenite // Tungstenite
Tungstenite(hyper_tungstenite::tungstenite::error::Error), Tungstenite(Box<hyper_tungstenite::tungstenite::error::Error>),
// URL Parse // URL Parse
UrlParse(url::ParseError), UrlParse(url::ParseError),
@ -382,7 +382,7 @@ impl From<toml::de::Error> for Error {
#[track_caller] #[track_caller]
fn from(err: toml::de::Error) -> Self { fn from(err: toml::de::Error) -> Self {
Error { Error {
inner: ChorusError::Config(err), inner: ChorusError::Config(Box::new(err)),
location: std::panic::Location::caller(), location: std::panic::Location::caller(),
} }
} }
@ -402,7 +402,7 @@ impl From<hyper::http::Error> for Error {
#[track_caller] #[track_caller]
fn from(err: hyper::http::Error) -> Self { fn from(err: hyper::http::Error) -> Self {
Error { Error {
inner: ChorusError::Http(err), inner: ChorusError::Http(Box::new(err)),
location: std::panic::Location::caller(), location: std::panic::Location::caller(),
} }
} }
@ -472,7 +472,7 @@ impl From<pocket_db::heed::Error> for Error {
#[track_caller] #[track_caller]
fn from(err: pocket_db::heed::Error) -> Self { fn from(err: pocket_db::heed::Error) -> Self {
Error { Error {
inner: ChorusError::PocketDbHeed(err), inner: ChorusError::PocketDbHeed(Box::new(err)),
location: std::panic::Location::caller(), location: std::panic::Location::caller(),
} }
} }
@ -492,7 +492,7 @@ impl From<tokio_rustls::rustls::Error> for Error {
#[track_caller] #[track_caller]
fn from(err: tokio_rustls::rustls::Error) -> Self { fn from(err: tokio_rustls::rustls::Error) -> Self {
Error { Error {
inner: ChorusError::Rustls(err), inner: ChorusError::Rustls(Box::new(err)),
location: std::panic::Location::caller(), location: std::panic::Location::caller(),
} }
} }
@ -502,7 +502,7 @@ impl From<hyper_tungstenite::tungstenite::error::Error> for Error {
#[track_caller] #[track_caller]
fn from(err: hyper_tungstenite::tungstenite::error::Error) -> Self { fn from(err: hyper_tungstenite::tungstenite::error::Error) -> Self {
Error { Error {
inner: ChorusError::Tungstenite(err), inner: ChorusError::Tungstenite(Box::new(err)),
location: std::panic::Location::caller(), location: std::panic::Location::caller(),
} }
} }
@ -572,7 +572,7 @@ impl From<std::string::FromUtf8Error> for Error {
#[track_caller] #[track_caller]
fn from(err: std::string::FromUtf8Error) -> Self { fn from(err: std::string::FromUtf8Error) -> Self {
Error { Error {
inner: ChorusError::FromUtf8(err), inner: ChorusError::FromUtf8(Box::new(err)),
location: std::panic::Location::caller(), location: std::panic::Location::caller(),
} }
} }

View File

@ -254,21 +254,30 @@ async fn websocket_thread(peer: HashedPeer, websocket: HyperWebsocket, origin: S
// Handle the websocket // Handle the websocket
if let Err(e) = ws_service.handle_websocket_stream().await { if let Err(e) = ws_service.handle_websocket_stream().await {
match e.inner { match e.inner {
ChorusError::Tungstenite(tungstenite::error::Error::Protocol( ChorusError::Tungstenite(ref t) => {
tungstenite::error::ProtocolError::ResetWithoutClosingHandshake, match *t.as_ref() {
)) => { tungstenite::error::Error::Protocol(
// So they disconnected ungracefully. tungstenite::error::ProtocolError::ResetWithoutClosingHandshake,
// No big deal, still SessionExit::Ok ) => {
msg = "Reset"; // So they disconnected ungracefully.
} // No big deal, still SessionExit::Ok
ChorusError::Tungstenite(tungstenite::error::Error::Io(ref ioerror)) => {
match ioerror.kind() {
std::io::ErrorKind::ConnectionReset
| std::io::ErrorKind::ConnectionAborted
| std::io::ErrorKind::UnexpectedEof => {
// no biggie.
msg = "Reset"; msg = "Reset";
} }
tungstenite::error::Error::Io(ref ioerror) => {
match ioerror.kind() {
std::io::ErrorKind::ConnectionReset
| std::io::ErrorKind::ConnectionAborted
| std::io::ErrorKind::UnexpectedEof => {
// no biggie.
msg = "Reset";
}
_ => {
log::error!(target: "Client", "{}: {}", peer, e);
session_exit = SessionExit::ErrorExit;
msg = "Error Exited";
}
}
}
_ => { _ => {
log::error!(target: "Client", "{}: {}", peer, e); log::error!(target: "Client", "{}: {}", peer, e);
session_exit = SessionExit::ErrorExit; session_exit = SessionExit::ErrorExit;