1use crate::json::JsonError;
2use crate::hpack::HPackError;
3use reqtls::{hex, Alert, BufferError, RlsError, ALPN};
4use std::array::TryFromSliceError;
5use std::convert::Infallible;
6use std::error::Error;
7use std::ffi::NulError;
8use std::fmt::{Display, Formatter};
9use std::io;
10use std::net::AddrParseError;
11use std::num::ParseIntError;
12use std::str::Utf8Error;
13use std::string::FromUtf8Error;
14use std::sync::PoisonError;
15#[cfg(feature = "aync")]
16use tokio::time::error::Elapsed;
17use crate::form_data::FormError;
18use crate::time::TimeError;
19
20#[derive(Debug)]
21pub enum HlsError {
22 NullPointer,
23 InvalidHeadSize,
24 PeerClosedConnection,
25 PayloadNone,
26 DecrypterNone,
27 EncrypterNone,
28 WsFrameTypeNone,
29 DataTooShort,
30 UnsupportedAlpn(ALPN),
31 Body(FormError),
32 Rls(RlsError),
33 HPack(HPackError),
34 Time(TimeError),
35 Currently(String),
36}
37
38impl From<&str> for HlsError {
39 fn from(s: &str) -> Self {
40 HlsError::Currently(s.to_string())
41 }
42}
43
44impl From<String> for HlsError {
45 fn from(s: String) -> Self {
46 HlsError::Currently(s)
47 }
48}
49
50impl From<FromUtf8Error> for HlsError {
51 fn from(e: FromUtf8Error) -> Self {
52 HlsError::Currently(e.to_string())
53 }
54}
55
56impl From<ParseIntError> for HlsError {
57 fn from(e: ParseIntError) -> Self {
58 HlsError::Currently(e.to_string())
59 }
60}
61
62impl Display for HlsError {
63 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
64 match self {
65 HlsError::Currently(e) => f.write_str(e),
66 HlsError::InvalidHeadSize => f.write_str("InvalidHeadSize"),
67 HlsError::PeerClosedConnection => f.write_str("PeerClosedConnection"),
68 HlsError::PayloadNone => f.write_str("PayloadNone"),
69 HlsError::DecrypterNone => f.write_str("DecrypterNone"),
70 HlsError::NullPointer => f.write_str("NonePointer"),
71 HlsError::EncrypterNone => f.write_str("EncrypterNone"),
72 HlsError::WsFrameTypeNone => f.write_str("WsFrameTypeNone"),
73 HlsError::DataTooShort => f.write_str("DataTooShort"),
74 HlsError::Rls(e) => write!(f, "RlsError({})", e),
75 HlsError::HPack(e) => write!(f, "HPack({})", e),
76 HlsError::Body(e) => write!(f, "Body({})", e),
77 HlsError::Time(e) => write!(f, "Time({:?})", e),
78 HlsError::UnsupportedAlpn(alpn) => write!(f, "UnsupportedAlpn({})", alpn),
79 }
80 }
81}
82
83impl From<TryFromSliceError> for HlsError {
84 fn from(value: TryFromSliceError) -> Self {
85 HlsError::Currently(value.to_string())
86 }
87}
88
89impl From<io::Error> for HlsError {
90 fn from(value: io::Error) -> Self {
91 HlsError::Currently(value.to_string())
92 }
93}
94
95impl From<Infallible> for HlsError {
96 fn from(value: Infallible) -> Self {
97 HlsError::Currently(value.to_string())
98 }
99}
100
101impl From<HPackError> for HlsError {
102 fn from(value: HPackError) -> Self {
103 HlsError::HPack(value)
104 }
105}
106
107impl From<JsonError> for HlsError {
108 fn from(value: JsonError) -> Self {
109 HlsError::Currently(value.to_string())
110 }
111}
112
113impl<T: 'static> From<PoisonError<T>> for HlsError {
114 fn from(value: PoisonError<T>) -> Self {
115 HlsError::Currently(value.to_string())
116 }
117}
118
119impl From<Utf8Error> for HlsError {
120 fn from(value: Utf8Error) -> Self {
121 HlsError::Currently(value.to_string())
122 }
123}
124
125impl From<RlsError> for HlsError {
126 fn from(value: RlsError) -> Self {
127 HlsError::Rls(value)
128 }
129}
130
131#[cfg(feature = "aync")]
132impl From<Elapsed> for HlsError {
133 fn from(value: Elapsed) -> Self {
134 HlsError::Currently(value.to_string())
135 }
136}
137
138impl From<HlsError> for io::Error {
139 fn from(err: HlsError) -> io::Error {
140 io::Error::other(err.to_string())
141 }
142}
143
144impl From<AddrParseError> for HlsError {
145 fn from(value: AddrParseError) -> Self {
146 HlsError::Currently(value.to_string())
147 }
148}
149
150impl From<hex::FromHexError> for HlsError {
151 fn from(value: hex::FromHexError) -> Self {
152 HlsError::Currently(value.to_string())
153 }
154}
155
156impl From<NulError> for HlsError {
157 fn from(value: NulError) -> Self {
158 HlsError::Currently(value.to_string())
159 }
160}
161
162impl From<Alert> for HlsError {
163 fn from(value: Alert) -> Self {
164 HlsError::Rls(RlsError::Alert(value))
165 }
166}
167
168impl From<BufferError> for HlsError {
169 fn from(value: BufferError) -> Self {
170 HlsError::Rls(RlsError::Buffer(value))
171 }
172}
173
174impl From<FormError> for HlsError {
175 fn from(value: FormError) -> Self {
176 HlsError::Body(value)
177 }
178}
179
180impl From<TimeError> for HlsError {
181 fn from(value: TimeError) -> Self {
182 HlsError::Time(value)
183 }
184}
185
186impl Error for HlsError {}
187
188
189pub type HlsResult<T> = Result<T, HlsError>;