use thiserror::Error;
use crate::resp::RespError;
pub type WalleResult<T> = Result<T, WalleError>;
#[derive(Error, Debug)]
pub enum WalleError {
#[error("expect {0} found {1}")]
DeclareNotMatch(&'static str, String),
#[error("Action send error")]
ActionSendError,
#[error("Action Response Timeout")]
ResponseTimeout,
#[error("RespMissmatch")]
RespNotMatch, #[error("{0:?}")]
RespError(RespError),
#[error("{0}")]
IO(#[from] std::io::Error),
#[error("OneBot is already started")]
AlreadyStarted,
#[error("OneBot is not started")]
NotStarted,
#[error("ExtendedMap missed key: {0}")]
MapMissedKey(String),
#[error("Type mismatch expect {0}, got {1}")]
ValueTypeNotMatch(String, String),
#[error("Illegal base64")]
IllegalBase64(String),
#[error("Bot not exist")]
BotNotExist,
#[error("{0}")]
Other(String),
}
impl serde::de::Error for WalleError {
fn custom<T>(msg: T) -> Self
where
T: std::fmt::Display,
{
WalleError::Other(format!("{}", msg))
}
}
impl serde::ser::Error for WalleError {
fn custom<T>(msg: T) -> Self
where
T: std::fmt::Display,
{
WalleError::Other(format!("{}", msg))
}
}