use std::fmt::{Debug, Display}; use tracing_subscriber::{EnvFilter, fmt, prelude::*}; #[derive(derive_more::Error, derive_more::Display, Debug)] #[display("No user info found")] pub struct NoUserInfo; #[derive(derive_more::Error, derive_more::Display, Debug)] #[display("Handler was already used")] pub struct HandlerUsed; #[derive(derive_more::Error, derive_more::Display, derive_more::From, Debug)] pub enum InvalidCommand { #[display("Invalid params")] InvalidParams, #[display("Not enough bytes in the name's hash")] InvalidOutputLength, #[display("Error decoding the values: {}", 0)] NameDecodingError(base64::DecodeError), #[display("Unknown locale passed into callback")] UnknownLocale, } pub fn init_logger() { tracing_subscriber::registry() .with(fmt::layer().pretty()) .with(EnvFilter::from_default_env()) .init(); } /// Handles an error. /// This function must be as cheap and generic as possible and must remain sync. /// If expensive or long action is required, a task should be spawned but not joined. pub fn handle_error(error: T) where T: Debug + Display, { tracing::error!(error_debug = ?error, error_message = %error); } pub struct ErrorHandler; impl teloxide::error_handlers::ErrorHandler for ErrorHandler { fn handle_error( self: std::sync::Arc, error: crate::Error, ) -> futures::prelude::future::BoxFuture<'static, ()> { handle_error(error); Box::pin(async {}) } }