Skip to main content

dspk_stream/
error.rs

1//! Errors of a stream session.
2
3use std::fmt;
4
5/// What went wrong in a stream session.
6#[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    /// The peer sent something the protocol does not allow.
27    #[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>;