Skip to main content

confium_net/
error.rs

1//! Errors for the Network crate.
2
3use snafu::Backtrace;
4use snafu::Snafu;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Snafu, Debug)]
9#[snafu(visibility(pub))]
10pub enum Error {
11    /// The transport URL could not be parsed.
12    #[snafu(display("Invalid transport URL '{}'", url))]
13    InvalidUrl {
14        url: String,
15        source: url::ParseError,
16        backtrace: Backtrace,
17    },
18
19    /// The URL scheme is not registered with any transport kind.
20    #[snafu(display("Unknown transport scheme '{}'", scheme))]
21    UnknownScheme {
22        scheme: String,
23        backtrace: Backtrace,
24    },
25
26    /// The URL was structurally valid but missing a part this scheme
27    /// requires (host, port, path, etc.).
28    #[snafu(display("Malformed '{}' URL '{}': {}", scheme, url, reason))]
29    MalformedUrl {
30        scheme: String,
31        url: String,
32        reason: &'static str,
33        backtrace: Backtrace,
34    },
35
36    /// The peer closed the transport cleanly.
37    #[snafu(display("Transport closed by peer"))]
38    Closed { backtrace: Backtrace },
39
40    /// A transport implementation reported an I/O-level failure
41    /// (connect refused, handshake abort, mid-stream protocol error).
42    /// The transport is unusable after this.
43    #[snafu(display("Transport I/O error: {}", source))]
44    Io {
45        source: std::io::Error,
46        backtrace: Backtrace,
47    },
48
49    /// The receive buffer was smaller than the next queued message.
50    /// The caller should retry with a larger buffer. The required size
51    /// is reported so the caller can size accordingly.
52    #[snafu(display("Buffer too small: needed {} bytes", needed))]
53    BufferTooSmall { needed: usize, backtrace: Backtrace },
54
55    /// The mock transport was configured to simulate a dropped message.
56    #[snafu(display("Message dropped by mock transport"))]
57    MockDrop { backtrace: Backtrace },
58
59    /// A built-in transport rejected an operation it does not support
60    /// (e.g. `listen` on a client-only transport).
61    #[snafu(display("Operation '{}' not supported by '{}'", op, scheme))]
62    Unsupported {
63        op: &'static str,
64        scheme: String,
65        backtrace: Backtrace,
66    },
67}