td_client/error.rs
1//! Request, transfer, authentication, and lifecycle failures.
2//!
3//! Failures with a waiting caller are returned through [`Result`]. Unsolicited
4//! native diagnostics use [`on_error`](crate::runtime::on_error), not every
5//! client's update queue. This crate chooses neither logging nor retry policy.
6//!
7//! A failed wait is not necessarily a failed side effect. For example, losing a
8//! reply during teardown does not prove a message was never accepted. Inspect
9//! the variant and the relevant operation's cancellation contract before retrying.
10//! Batch sends expose independent inner results so partial success is preserved.
11
12use std::result;
13
14use td_types::enums::AuthorizationState;
15use td_types::types;
16
17use crate::message::MessageKey;
18
19/// The result of a client operation; the default success value is `()`.
20pub type Result<T = ()> = result::Result<T, Error>;
21
22/// An inspectable client failure.
23///
24/// `TDLib` codes and messages are preserved rather than classified into a
25/// library-defined retry policy. This enum does not represent every unsolicited
26/// update or native log message.
27#[derive(Debug, thiserror::Error)]
28pub enum Error {
29 /// `TDLib` reported an error, preserving its original code and message.
30 ///
31 /// Returned for request failures or delivered as an unsolicited diagnostic
32 /// through [`on_error`](crate::runtime::on_error).
33 #[error("TDLib: {} {}", .0.code, .0.message)]
34 Td(types::error),
35 /// A request could not be serialized or native output could not be decoded.
36 #[error("JSON: {0}")]
37 Json(#[from] serde_json::Error),
38 /// The bot helper encountered an authorization state it does not handle.
39 #[error("unexpected auth state: {0:?}")]
40 Auth(AuthorizationState),
41 /// Token-triggered cleanup won according to the operation's cancellation rules.
42 #[error("operation cancelled")]
43 Cancelled,
44 /// A tracked send failed; contains its temporary key and the native error.
45 #[error("message {} in chat {} failed: {} {}", .0.message_id, .0.chat_id, .1.code, .1.message)]
46 MessageFailed(MessageKey, types::error),
47 /// A tracked temporary message was deleted by a non-cache update.
48 #[error("message {} in chat {} was deleted while being sent", .0.message_id, .0.chat_id)]
49 MessageDeleted(MessageKey),
50 /// The native response did not have the shape required by this operation.
51 #[error("unexpected TDLib response: {0}")]
52 UnexpectedResponse(&'static str),
53 /// The owner is unavailable, admission is closed, or a reply was abandoned during teardown.
54 #[error("client disconnected")]
55 Disconnected,
56}