modbus_relay/errors/
connection.rs

1use thiserror::Error;
2
3use super::BackoffError;
4
5#[derive(Error, Debug)]
6pub enum ConnectionError {
7    #[error("Connection limit exceeded: {0}")]
8    LimitExceeded(String),
9
10    #[error("Connection timed out: {0}")]
11    Timeout(String),
12
13    #[error("Invalid connection state: {0}")]
14    InvalidState(String),
15
16    #[error("Connection rejected: {0}")]
17    Rejected(String),
18
19    #[error("Connection disconnected")]
20    Disconnected,
21
22    #[error("Backoff error: {0}")]
23    Backoff(#[from] BackoffError),
24}
25
26impl ConnectionError {
27    pub fn limit_exceeded(details: impl Into<String>) -> Self {
28        ConnectionError::LimitExceeded(details.into())
29    }
30
31    pub fn timeout(details: impl Into<String>) -> Self {
32        ConnectionError::Timeout(details.into())
33    }
34
35    pub fn invalid_state(details: impl Into<String>) -> Self {
36        ConnectionError::InvalidState(details.into())
37    }
38
39    pub fn rejected(details: impl Into<String>) -> Self {
40        ConnectionError::Rejected(details.into())
41    }
42}