tcp_client/
errors.rs

1//! The common errors.
2
3use std::time::Duration;
4use tcp_handler::protocols::common::{PacketError, StarterError};
5use thiserror::Error;
6
7/// Error when send/recv messages.
8#[derive(Error, Debug)]
9pub enum Error {
10    /// Sending/receiving timeout. See [`get_receive_timeout`].
11    #[error("Network timeout: {} after {1:?}.", if *.0 { "Connecting" } else { "Receiving" })]
12    Timeout(bool, Duration),
13
14    /// During init protocol. From [`tcp_handler`][crate::tcp_handler].
15    #[error("During io packet: {0}")]
16    StarterError(#[from] StarterError),
17
18    /// During io packet. From [`tcp_handler`][crate::tcp_handler].
19    #[error("During io packet: {0}")]
20    PacketError(#[from] PacketError),
21
22    /// During read/write data from [`bytes`][crate::bytes].
23    #[error("During read/write data: {0}")]
24    DataError(#[from] std::io::Error),
25
26    /// During check if the server supports the function.
27    #[error("The server is not available.")]
28    ServerDenied,
29}
30
31/// Type alias of `std::result::Result<T, Error>`
32pub type Result<T> = std::result::Result<T, Error>;