1use std::fmt;
4
5#[derive(Debug, thiserror::Error)]
7pub enum StreamError {
8 #[error("I/O: {0}")]
9 Io(#[from] std::io::Error),
10 #[error("TLS: {0}")]
11 Tls(String),
12 #[error("connect: {0}")]
13 Connect(#[from] quinn::ConnectError),
14 #[error("connection: {0}")]
15 Connection(#[from] quinn::ConnectionError),
16 #[error("read: {0}")]
17 Read(#[from] quinn::ReadExactError),
18 #[error("write: {0}")]
19 Write(#[from] quinn::WriteError),
20 #[error("message of {len} bytes exceeds the {max}-byte limit")]
21 TooLarge { len: usize, max: usize },
22 #[error("stream ended inside a message")]
23 Truncated,
24 #[error("decode: {0}")]
25 Decode(#[from] prost::DecodeError),
26 #[error("protocol: {0}")]
28 Protocol(String),
29 #[error(transparent)]
30 Dsp(#[from] dspk_core::DspError),
31}
32
33impl StreamError {
34 pub(crate) fn protocol(message: impl fmt::Display) -> Self {
35 Self::Protocol(message.to_string())
36 }
37}
38
39pub type StreamResult<T> = Result<T, StreamError>;