Imporved logging and added debug information to get backtraces when errors are encountered
This commit is contained in:
@ -40,7 +40,10 @@ pub enum CallbackCommand {
|
||||
impl CallbackCommand {
|
||||
pub fn from_query(q: CallbackQuery) -> Option<Self> {
|
||||
q.message?;
|
||||
q.data?.parse().inspect_err(|err| log::error!("{err}")).ok()
|
||||
q.data?
|
||||
.parse()
|
||||
.inspect_err(|err| log::error!("{err:?}"))
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ pub async fn change_locale(
|
||||
let is_successful = new_locale
|
||||
.update(user_id, &db)
|
||||
.await
|
||||
.inspect_err(|err| log::error!("{err}"))
|
||||
.inspect_err(|err| log::error!("{err:?}"))
|
||||
.unwrap_or(false);
|
||||
|
||||
if !is_successful {
|
||||
|
@ -27,7 +27,7 @@ async fn get_master_pass(
|
||||
&locale.everything_was_deleted
|
||||
}
|
||||
(Err(err), _) | (_, Err(err)) => {
|
||||
error!("{}", crate::Error::from(err));
|
||||
error!("{:?}", crate::Error::from(err));
|
||||
txn.rollback().await?;
|
||||
&locale.something_went_wrong
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::prelude::*;
|
||||
use anyhow::Result;
|
||||
use entity::locale::LocaleType;
|
||||
use log::error;
|
||||
use std::future::Future;
|
||||
@ -13,16 +12,16 @@ pub struct LocaleStore {
|
||||
}
|
||||
|
||||
impl LocaleStore {
|
||||
pub fn init() -> Result<()> {
|
||||
let ru = serde_yaml::from_slice(include_bytes!("../locales/ru.yaml"))?;
|
||||
let eng = serde_yaml::from_slice(include_bytes!("../locales/eng.yaml"))?;
|
||||
pub fn init() {
|
||||
let ru = serde_yaml::from_slice(include_bytes!("../locales/ru.yaml"))
|
||||
.expect("Error parsing russian locale");
|
||||
let eng = serde_yaml::from_slice(include_bytes!("../locales/eng.yaml"))
|
||||
.expect("Error parsing english locale");
|
||||
|
||||
assert!(
|
||||
LOCALES.set(Self { eng, ru }).is_ok(),
|
||||
"Locales are already intialized"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +153,7 @@ impl LocaleTypeExt for LocaleType {
|
||||
match Self::get_from_db(from.id.0, db).await {
|
||||
Ok(Some(locale)) => return locale,
|
||||
Ok(None) => (),
|
||||
Err(err) => error!("{err}"),
|
||||
Err(err) => error!("{err:?}"),
|
||||
}
|
||||
|
||||
from.language_code
|
||||
|
@ -87,9 +87,9 @@ fn get_dispatcher(
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let _ = dotenv();
|
||||
pretty_env_logger::init();
|
||||
pretty_env_logger::init_timed();
|
||||
|
||||
locales::LocaleStore::init()?;
|
||||
locales::LocaleStore::init();
|
||||
|
||||
let token = env::var("TOKEN").expect("expected TOKEN in the enviroment");
|
||||
let database_url = env::var("DATABASE_URL").expect("expected DATABASE_URL in the enviroment");
|
||||
|
@ -13,7 +13,12 @@ async fn check_master_pass(
|
||||
) -> crate::Result<Option<String>> {
|
||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||
let Some(model) = MasterPass::get(user_id, db).await? else {
|
||||
error!("User was put into the GetMasterPass state with no master password set");
|
||||
error!(
|
||||
"{:?}",
|
||||
anyhow::anyhow!(
|
||||
"User was put into the GetMasterPass state with no master password set"
|
||||
)
|
||||
);
|
||||
return Ok(Some(locale.master_password_is_not_set.to_owned()));
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,7 @@ impl MessageIds {
|
||||
|
||||
let result = join!(self.delete(bot), send_request.send());
|
||||
if let Err(err) = result.0 {
|
||||
log::error!("{err}");
|
||||
log::error!("{err:?}");
|
||||
}
|
||||
*self = Self::from(&result.1?);
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user