use std::{convert::Infallible, fmt};
use serde::{Deserialize, Serialize};
use crate::parser::ParserError;
#[derive(Debug, thiserror::Error, Serialize, Deserialize, Clone)]
pub enum SocketError {
#[error("internal channel full error")]
InternalChannelFull,
#[error("socket closed")]
Closed,
}
#[derive(Debug, thiserror::Error)]
pub struct AdapterError(#[from] pub Box<dyn std::error::Error + Send>);
impl fmt::Display for AdapterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
impl From<Infallible> for AdapterError {
fn from(_: Infallible) -> Self {
panic!("Infallible should never be constructed, this is a bug")
}
}
#[derive(thiserror::Error, Debug)]
pub enum BroadcastError {
#[error("Error sending data through the engine.io socket: {0:?}")]
Socket(Vec<SocketError>),
#[error("Error serializing packet: {0:?}")]
Serialize(#[from] ParserError),
#[error("Adapter error: {0}")]
Adapter(#[from] AdapterError),
}
impl From<Vec<SocketError>> for BroadcastError {
fn from(value: Vec<SocketError>) -> Self {
assert!(
!value.is_empty(),
"Cannot construct a BroadcastError from an empty vec of SocketError"
);
Self::Socket(value)
}
}