Skip to main content

futu_core/
error.rs

1use thiserror::Error;
2
3/// **Stable API** — FutuOpenD 统一错误类型。
4///
5/// 跨 10+ crate 共享的错误枚举,`#[non_exhaustive]` 表示下版可能新增变体
6/// (不算 breaking)。新增已有变体字段属于 breaking。
7#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum FutuError {
10    #[error("网络错误: {0}")]
11    Network(#[from] std::io::Error),
12
13    #[error("协议解析错误: {0}")]
14    Codec(String),
15
16    #[error("Protobuf 解码失败: {0}")]
17    Proto(#[from] prost::DecodeError),
18
19    #[error("服务端返回错误, ret_type={ret_type}, msg={msg}")]
20    ServerError { ret_type: i32, msg: String },
21
22    #[error("连接超时")]
23    Timeout,
24
25    #[error("未初始化")]
26    NotInitialized,
27
28    #[error("加密错误: {0}")]
29    Encryption(String),
30
31    #[error("SHA1 校验失败")]
32    Sha1Mismatch,
33
34    #[error("无效的协议帧头")]
35    InvalidHeader,
36}
37
38/// **Stable API** — `Result<T, FutuError>` 的短别名。
39///
40/// 几乎所有 futu-* crate 的 pub fn signature 都用它。
41pub type Result<T> = std::result::Result<T, FutuError>;