Skip to main content

ralph_telegram/
error.rs

1use thiserror::Error;
2
3/// Result type alias for telegram operations.
4pub type TelegramResult<T> = std::result::Result<T, TelegramError>;
5
6/// Errors that can occur during Telegram bot operations.
7#[derive(Debug, Error)]
8pub enum TelegramError {
9    /// Bot token is missing from config and environment.
10    #[error(
11        "telegram bot token not found: set RALPH_TELEGRAM_BOT_TOKEN or configure human.telegram.bot_token"
12    )]
13    MissingBotToken,
14
15    /// Failed to start the Telegram bot (network, auth, etc.).
16    #[error("failed to start telegram bot: {0}")]
17    Startup(String),
18
19    /// Failed to send a message after retries.
20    #[error("failed to send telegram message after {attempts} attempts: {reason}")]
21    Send { attempts: u32, reason: String },
22
23    /// Failed to receive messages.
24    #[error("failed to receive telegram messages: {0}")]
25    Receive(String),
26
27    /// Timed out waiting for a human response.
28    #[error("timed out waiting for human response after {timeout_secs}s")]
29    ResponseTimeout { timeout_secs: u64 },
30
31    /// Failed to read or write state file.
32    #[error("state persistence error: {0}")]
33    State(#[from] std::io::Error),
34
35    /// Failed to parse state JSON.
36    #[error("state parse error: {0}")]
37    StateParse(#[from] serde_json::Error),
38
39    /// Failed to write event to JSONL.
40    #[error("event write error: {0}")]
41    EventWrite(String),
42}