asterisk_rs_core/
error.rs1#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7 #[error("connection failed: {0}")]
8 Connection(#[from] ConnectionError),
9
10 #[error("authentication failed: {0}")]
11 Auth(#[from] AuthError),
12
13 #[error("operation timed out: {0}")]
14 Timeout(#[from] TimeoutError),
15
16 #[error("protocol error: {0}")]
17 Protocol(#[from] ProtocolError),
18
19 #[error("I/O error: {0}")]
20 Io(#[from] std::io::Error),
21}
22
23pub type Result<T> = std::result::Result<T, Error>;
24
25#[derive(Debug, thiserror::Error)]
26#[non_exhaustive]
27pub enum ConnectionError {
28 #[error("failed to connect to {address}: {source}")]
29 ConnectFailed {
30 address: String,
31 source: std::io::Error,
32 },
33
34 #[error("connection closed unexpectedly")]
35 Closed,
36
37 #[error("TLS handshake failed: {0}")]
38 Tls(String),
39
40 #[error("DNS resolution failed for {host}: {source}")]
41 DnsResolution {
42 host: String,
43 source: std::io::Error,
44 },
45}
46
47#[derive(Debug, thiserror::Error)]
48#[non_exhaustive]
49pub enum AuthError {
50 #[error("login rejected: {reason}")]
51 Rejected { reason: String },
52
53 #[error("invalid credentials")]
54 InvalidCredentials,
55
56 #[error("challenge-response failed")]
57 ChallengeFailed,
58}
59
60#[derive(Debug, thiserror::Error)]
61#[non_exhaustive]
62pub enum TimeoutError {
63 #[error("action timed out after {elapsed:?}")]
64 Action { elapsed: std::time::Duration },
65
66 #[error("connection timed out after {elapsed:?}")]
67 Connection { elapsed: std::time::Duration },
68}
69
70#[derive(Debug, thiserror::Error)]
71#[non_exhaustive]
72pub enum ProtocolError {
73 #[error("malformed message: {details}")]
74 MalformedMessage { details: String },
75
76 #[error("unexpected response: expected {expected}, got {actual}")]
77 UnexpectedResponse { expected: String, actual: String },
78
79 #[error("unsupported protocol version: {version}")]
80 UnsupportedVersion { version: String },
81}