socketioxide_core/
errors.rs1use std::{convert::Infallible, fmt};
3
4use serde::{Deserialize, Serialize};
5
6use crate::parser::ParserError;
7
8#[derive(Debug, thiserror::Error, Serialize, Deserialize, Clone)]
10pub enum SocketError {
11    #[error("internal channel full error")]
16    InternalChannelFull,
17
18    #[error("socket closed")]
20    Closed,
21}
22
23#[derive(Debug, thiserror::Error)]
25pub struct AdapterError(#[from] pub Box<dyn std::error::Error + Send>);
26impl fmt::Display for AdapterError {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        fmt::Display::fmt(&self.0, f)
29    }
30}
31impl From<Infallible> for AdapterError {
32    fn from(_: Infallible) -> Self {
33        panic!("Infallible should never be constructed, this is a bug")
34    }
35}
36
37#[derive(thiserror::Error, Debug)]
39pub enum BroadcastError {
40    #[error("Error sending data through the engine.io socket: {0:?}")]
43    Socket(Vec<SocketError>),
44
45    #[error("Error serializing packet: {0:?}")]
47    Serialize(#[from] ParserError),
48
49    #[error("Adapter error: {0}")]
51    Adapter(#[from] AdapterError),
52}
53
54impl From<Vec<SocketError>> for BroadcastError {
55    fn from(value: Vec<SocketError>) -> Self {
56        assert!(
57            !value.is_empty(),
58            "Cannot construct a BroadcastError from an empty vec of SocketError"
59        );
60        Self::Socket(value)
61    }
62}