use std::fmt;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("platform error ({platform}): {message}")]
Platform {
platform: &'static str,
message: String,
},
#[error("no platforms registered - add at least one with Bot::add_platform")]
NoPlatforms,
#[error("handler error: {0}")]
Handler(Box<dyn std::error::Error + Send + Sync>),
#[error("{0}")]
Other(String),
}
impl Error {
pub fn platform<E: fmt::Display>(platform: &'static str, err: E) -> Self {
Self::Platform {
platform,
message: err.to_string(),
}
}
}
impl From<std::env::VarError> for Error {
fn from(e: std::env::VarError) -> Self {
Self::Other(format!("missing env var: {e}"))
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Other(format!("io error: {e}"))
}
}