1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum TelegramBotError {
8 #[error("daemon connection failed: {0}")]
10 DaemonConnection(String),
11
12 #[error("daemon RPC error: {0}")]
14 DaemonRpc(String),
15
16 #[error("no session for chat {0}")]
18 #[allow(dead_code)]
19 NoSession(i64),
20
21 #[error("turn already in progress for chat {0}")]
23 #[allow(dead_code)]
24 TurnInProgress(i64),
25
26 #[error("telegram API error: {0}")]
28 #[allow(dead_code)]
29 Telegram(String),
30
31 #[error("configuration error: {0}")]
33 Config(String),
34}
35
36pub type TelegramResult<T> = Result<T, TelegramBotError>;
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn error_display_daemon_connection() {
45 let err = TelegramBotError::DaemonConnection("refused".to_string());
46 assert_eq!(err.to_string(), "daemon connection failed: refused");
47 }
48
49 #[test]
50 fn error_display_daemon_rpc() {
51 let err = TelegramBotError::DaemonRpc("timeout".to_string());
52 assert_eq!(err.to_string(), "daemon RPC error: timeout");
53 }
54
55 #[test]
56 fn error_display_no_session() {
57 let err = TelegramBotError::NoSession(42);
58 assert_eq!(err.to_string(), "no session for chat 42");
59 }
60
61 #[test]
62 fn error_display_turn_in_progress() {
63 let err = TelegramBotError::TurnInProgress(99);
64 assert_eq!(err.to_string(), "turn already in progress for chat 99");
65 }
66
67 #[test]
68 fn error_display_telegram() {
69 let err = TelegramBotError::Telegram("rate limited".to_string());
70 assert_eq!(err.to_string(), "telegram API error: rate limited");
71 }
72
73 #[test]
74 fn error_display_config() {
75 let err = TelegramBotError::Config("missing token".to_string());
76 assert_eq!(err.to_string(), "configuration error: missing token");
77 }
78
79 #[test]
80 fn error_is_send_and_sync() {
81 fn assert_send_sync<T: Send + Sync>() {}
82 assert_send_sync::<TelegramBotError>();
83 }
84}