Skip to main content

hyperi_rustlib/transport/
error.rs

1// Project:   hyperi-rustlib
2// File:      src/transport/error.rs
3// Purpose:   Transport error types
4// Language:  Rust
5//
6// License:   BUSL-1.1
7// Copyright: (c) 2026 HYPERI PTY LIMITED
8
9use thiserror::Error;
10
11/// Result type for transport operations.
12pub type TransportResult<T> = Result<T, TransportError>;
13
14/// Errors that can occur during transport operations.
15#[derive(Debug, Error)]
16pub enum TransportError {
17    /// Configuration error (missing or invalid config).
18    #[error("transport config error: {0}")]
19    Config(String),
20
21    /// Connection error (network, auth, etc.).
22    #[error("transport connection error: {0}")]
23    Connection(String),
24
25    /// Send operation failed.
26    #[error("transport send error: {0}")]
27    Send(String),
28
29    /// Receive operation failed.
30    #[error("transport receive error: {0}")]
31    Recv(String),
32
33    /// Commit/acknowledge operation failed.
34    #[error("transport commit error: {0}")]
35    Commit(String),
36
37    /// Transport is closed or shutting down.
38    #[error("transport closed")]
39    Closed,
40
41    /// Timeout waiting for operation.
42    #[error("transport operation timed out")]
43    Timeout,
44
45    /// Backpressure - transport cannot accept more messages.
46    #[error("transport backpressure")]
47    Backpressure,
48
49    /// Internal transport error.
50    #[error("transport internal error: {0}")]
51    Internal(String),
52
53    /// Admin operation error (topic/partition management).
54    #[error("transport admin error: {0}")]
55    Admin(String),
56}
57
58impl TransportError {
59    /// Returns true if this error is recoverable (retry may succeed).
60    #[must_use]
61    pub fn is_recoverable(&self) -> bool {
62        matches!(self, Self::Timeout | Self::Backpressure)
63    }
64
65    /// Returns true if this error indicates the transport is unusable.
66    #[must_use]
67    pub fn is_fatal(&self) -> bool {
68        matches!(self, Self::Closed | Self::Config(_))
69    }
70}