Skip to main content

http_quik/
error.rs

1//! Unified error surface for the `quik` transport stack.
2//!
3//! Every layer in the engine—TLS negotiation, HTTP/2 signaling, and proxy
4//! handshakes—reports through this boundary. A stable error surface is essential
5//! for higher-level session management to perform connection pooling, identity
6//! rotation, and retry logic without inspecting subsystem-specific internals.
7
8use thiserror::Error;
9
10/// Errors that can occur during high-fidelity transport operations.
11///
12/// This enum categorizes failures across the entire protocol stack, from low-level
13/// TCP dialing to high-level HTTP/2 frame signaling.
14#[derive(Debug, Error)]
15pub enum Error {
16    /// Failure during the construction of the BoringSSL context.
17    ///
18    /// This usually indicates an invalid cipher list, unsupported curve
19    /// configuration, or a missing FFI symbol in the linked BoringSSL binary.
20    #[error("failed to build TLS connector: {0}")]
21    TlsBuild(#[from] boring::error::ErrorStack),
22
23    /// Failure during the TLS handshake with the remote peer.
24    ///
25    /// These errors often stem from peer-side fingerprint validation, protocol
26    /// version mismatches, or failures in the ALPN/ALPS negotiation phase.
27    #[error("TLS handshake failed: {0}")]
28    TlsHandshake(#[from] tokio_boring::HandshakeError<tokio::net::TcpStream>),
29
30    /// Failure during the HTTP/2 handshake or frame signaling.
31    ///
32    /// This error is returned when the remote peer violates the H2 protocol or
33    /// when the internal state machine fails to replicate the required Chrome
34    /// behavior (e.g., SETTINGS frame ordering).
35    #[error("http/2 handshake failed: {0}")]
36    Http2(#[from] http2::Error),
37
38    /// Standard I/O failure during connection establishment or data transfer.
39    ///
40    /// This covers TCP timeout, connection reset, and other OS-level network errors.
41    #[error("connection failed: {0}")]
42    Connect(#[from] std::io::Error),
43
44    /// Fingerprint verification failed against a reference validator.
45    ///
46    /// This is an orchestration error that occurs when the actual wire behavior
47    /// (JA3/JA4/Akamai) deviates from the constants defined in the identity profile.
48    #[error("fingerprint verification failed: {0}")]
49    Verify(String),
50
51    /// The provided URL is malformed or uses an unsupported scheme.
52    #[error("invalid url: {0}")]
53    InvalidUrl(String),
54}
55
56pub type Result<T> = std::result::Result<T, Error>;