Skip to main content

pyrosql_protocol/
error.rs

1//! Error types for the PyroLink QUIC transport.
2
3use thiserror::Error;
4
5/// Errors that can occur in the PyroLink layer.
6#[derive(Debug, Error)]
7pub enum PyroLinkError {
8    /// A QUIC connection-level error reported by quinn.
9    #[error("QUIC connection error: {0}")]
10    Connection(#[from] quinn::ConnectionError),
11
12    /// Failed to accept or open a QUIC stream.
13    #[error("QUIC stream error: {0}")]
14    Stream(String),
15
16    /// An I/O error on the underlying QUIC stream.
17    #[error("stream I/O error: {0}")]
18    Io(#[from] std::io::Error),
19
20    /// The wire frame received from the client was malformed.
21    #[error("framing error: {0}")]
22    Framing(String),
23
24    /// The RPC type byte was not recognised.
25    #[error("unknown RPC type byte: {0:#04x}")]
26    UnknownRpcType(u8),
27
28    /// TLS configuration was invalid.
29    #[error("TLS configuration error: {0}")]
30    Tls(String),
31
32    /// The server endpoint could not be bound to the requested address.
33    #[error("bind error: {0}")]
34    Bind(String),
35
36    /// An error propagated from the Flight SQL layer.
37    #[error("Flight SQL error: {0}")]
38    Flight(String),
39
40    /// An internal, unexpected error.
41    #[error("internal error: {0}")]
42    Internal(String),
43}
44
45impl From<quinn::ReadExactError> for PyroLinkError {
46    fn from(e: quinn::ReadExactError) -> Self {
47        match e {
48            quinn::ReadExactError::FinishedEarly(n) => {
49                Self::Framing(format!("stream ended {n} bytes early"))
50            }
51            quinn::ReadExactError::ReadError(re) => Self::Stream(re.to_string()),
52        }
53    }
54}