walle_core/
error.rs

1use thiserror::Error;
2
3use crate::resp::RespError;
4
5pub type WalleResult<T> = Result<T, WalleError>;
6
7/// Walle-core errors
8#[derive(Error, Debug)]
9pub enum WalleError {
10    // event
11    #[error("expect {0} found {1}")]
12    DeclareNotMatch(&'static str, String),
13    // action
14    #[error("Action send error")]
15    ActionSendError,
16    // resp
17    #[error("Action Response Timeout")]
18    ResponseTimeout,
19    #[error("RespMissmatch")]
20    RespNotMatch, //todo
21    #[error("{0:?}")]
22    RespError(RespError),
23    // server
24    #[error("{0}")]
25    IO(#[from] std::io::Error),
26    // Running Time Error
27    #[error("OneBot is already started")]
28    AlreadyStarted,
29    #[error("OneBot is not started")]
30    NotStarted,
31
32    // Extended
33    #[error("ExtendedMap missed key: {0}")]
34    MapMissedKey(String),
35    #[error("Type mismatch expect {0}, got {1}")]
36    ValueTypeNotMatch(String, String),
37    #[error("Illegal base64")]
38    IllegalBase64(String),
39
40    // OBC
41    #[error("Bot not exist")]
42    BotNotExist,
43
44    #[error("{0}")]
45    Other(String),
46}
47
48impl serde::de::Error for WalleError {
49    fn custom<T>(msg: T) -> Self
50    where
51        T: std::fmt::Display,
52    {
53        WalleError::Other(format!("{}", msg))
54    }
55}
56
57impl serde::ser::Error for WalleError {
58    fn custom<T>(msg: T) -> Self
59    where
60        T: std::fmt::Display,
61    {
62        WalleError::Other(format!("{}", msg))
63    }
64}