1use std::fmt::Debug;
3
4use nom::Needed;
5use thiserror::Error;
6
7pub enum IncompleteResult<T> {
14 Ok(T),
15 Incomplete(Needed),
16 Err(ParseError),
17}
18
19#[derive(Debug, Error)]
21pub enum ParseError {
22 #[error("json error: {0}")]
23 Json(#[from] serde_json::Error),
24 #[error("not a valid int32 big endian")]
25 Int32BE,
26 #[error("unknown websocket pack protocol")]
27 UnknownProtocol,
28 #[error("error when parsing packet struct")]
29 PacketError(String),
30 #[error("error when decompressing packet buffer: {0}")]
31 ZlibError(#[from] std::io::Error),
32}
33
34#[cfg(feature = "not-send")]
35pub(crate) type BoxedError = Box<dyn std::error::Error>;
36
37#[cfg(not(feature = "not-send"))]
38pub(crate) type BoxedError = Box<dyn std::error::Error + Send + Sync>;
39
40#[derive(Debug, Error)]
42#[error("error when making http request: {0}")]
43pub struct BuildError(#[source] pub(crate) BoxedError);
44
45#[derive(Debug, Error)]
49pub enum StreamError<E> {
50 #[error("parse error: {0}")]
51 Parse(#[from] ParseError),
52 #[error("ws error: {0}")]
53 WebSocket(E),
54 #[error("io error: {0}")]
55 IO(#[from] std::io::Error),
56}
57
58impl<E> StreamError<E> {
59 pub const fn from_ws_error(e: E) -> Self {
60 Self::WebSocket(e)
61 }
62}