1use std::io;
2
3use futures::channel::mpsc::SendError;
4
5#[derive(thiserror::Error, Debug)]
6pub enum HalaIoError {
7 #[error("{0}")]
8 StdIoError(#[from] std::io::Error),
9
10 #[error("{0}")]
11 SendError(#[from] SendError),
12
13 #[cfg(feature = "quice")]
14 #[error("{0}")]
15 QuicheError(#[from] quiche::Error),
16
17 #[cfg(feature = "quice")]
18 #[error("{0}")]
19 Unspecified(#[from] ring::error::Unspecified),
20}
21
22impl From<HalaIoError> for std::io::Error {
23 fn from(value: HalaIoError) -> Self {
24 match value {
25 HalaIoError::SendError(send_error) => {
26 std::io::Error::new(std::io::ErrorKind::BrokenPipe, send_error)
27 }
28 HalaIoError::StdIoError(io_error) => io_error,
29 #[cfg(feature = "quice")]
30 HalaIoError::QuicheError(err) => match err {
31 quiche::Error::StreamStopped(_) | quiche::Error::InvalidStreamState(_) => {
32 std::io::Error::new(std::io::ErrorKind::BrokenPipe, err)
33 }
34 _ => std::io::Error::new(std::io::ErrorKind::Other, err),
35 },
36 #[cfg(feature = "quice")]
37 HalaIoError::Unspecified(err) => std::io::Error::new(std::io::ErrorKind::Other, err),
38 }
39 }
40}
41
42pub fn into_io_error<E: Into<HalaIoError>>(error: E) -> io::Error {
43 let err: HalaIoError = error.into();
44
45 err.into()
46}