1use std::io;
4
5use mikrotik_proto::error::{ConnectionError, LoginError, ProtocolError};
6use mikrotik_proto::response::TrapResponse;
7use thiserror::Error;
8
9pub type DeviceResult<T> = Result<T, DeviceError>;
11
12#[derive(Error, Debug, Clone, Copy)]
14pub enum ActorError {
15 #[error("Failed to send command: actor is unavailable (channel closed)")]
17 CommandSendFailed,
18
19 #[error("Login response not received: actor shut down during login")]
21 LoginResponseLost,
22}
23
24#[derive(Error, Debug)]
26pub enum DeviceError {
27 #[error("Connection error: {0}")]
29 Connection(#[from] io::Error),
30
31 #[error("Authentication failed: {response}")]
33 Authentication {
34 response: TrapResponse,
36 },
37
38 #[error("Actor error: {0}")]
40 Actor(#[from] ActorError),
41
42 #[error("Protocol error: {0}")]
44 Protocol(#[from] ProtocolError),
45
46 #[error("Connection state error: {0}")]
48 ConnectionState(#[from] ConnectionError),
49
50 #[error("Login error: {0}")]
52 Login(#[from] LoginError),
53
54 #[cfg(feature = "tokio-tls")]
56 #[error("TLS error: {0}")]
57 Tls(#[from] rustls::Error),
58
59 #[error("Connection closed by remote device")]
61 ConnectionClosed,
62}
63
64impl<T> From<tokio::sync::mpsc::error::SendError<T>> for DeviceError {
65 fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self {
66 DeviceError::Actor(ActorError::CommandSendFailed)
67 }
68}