Imporved logging and added debug information to get backtraces when errors are encountered

This commit is contained in:
StNicolay 2024-04-23 18:19:35 +03:00
parent 305b796d51
commit 1b9fa77b13
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
10 changed files with 66 additions and 65 deletions

86
Cargo.lock generated
View File

@ -60,6 +60,9 @@ name = "anyhow"
version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519"
dependencies = [
"backtrace",
]
[[package]]
name = "aquamarine"
@ -493,9 +496,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "fastrand"
version = "2.0.2"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984"
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
[[package]]
name = "finl_unicode"
@ -677,9 +680,9 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.14.3"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [
"ahash",
"allocator-api2",
@ -945,9 +948,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
[[package]]
name = "lock_api"
version = "0.4.11"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
@ -1113,9 +1116,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "parking_lot"
version = "0.12.1"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb"
dependencies = [
"lock_api",
"parking_lot_core",
@ -1123,15 +1126,15 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.9.9"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"redox_syscall 0.5.1",
"smallvec",
"windows-targets 0.48.5",
"windows-targets 0.52.5",
]
[[package]]
@ -1379,6 +1382,15 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
dependencies = [
"bitflags 2.5.0",
]
[[package]]
name = "regex"
version = "1.10.4"
@ -1504,9 +1516,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.33"
version = "0.38.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3cc72858054fcff6d7dea32df2aeaee6a7c24227366d7ea429aada2f26b16ad"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
dependencies = [
"bitflags 2.5.0",
"errno",
@ -1517,9 +1529,9 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.21.11"
version = "0.21.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4"
checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e"
dependencies = [
"log",
"ring",
@ -1597,18 +1609,18 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca"
[[package]]
name = "serde"
version = "1.0.198"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.198"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
dependencies = [
"proc-macro2",
"quote",
@ -1721,9 +1733,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "socket2"
version = "0.5.6"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
dependencies = [
"libc",
"windows-sys 0.52.0",
@ -2520,41 +2532,19 @@ version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9"
dependencies = [
"redox_syscall",
"redox_syscall 0.4.1",
"wasite",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.6"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
dependencies = [
"winapi",
"windows-sys 0.52.0",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.48.0"

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
strip = true
debug = 1
lto = true
codegen-units = 1
@ -23,11 +23,14 @@ workspace = true
[dependencies]
ahash = "0.8"
anyhow = "1"
anyhow = { version = "1", features = ["backtrace"] }
arrayvec = "0.7"
base64 = "0.22"
cryptography = { version = "0.1", path = "cryptography" }
derive_more = { version = "0.99.17", default-features = false, features = ["deref", "display"] }
derive_more = { version = "0.99", default-features = false, features = [
"deref",
"display",
] }
dotenvy = "0.15"
entity = { version = "0.1", path = "entity" }
futures = "0.3"

View File

@ -13,6 +13,7 @@ COPY . .
RUN cargo b -r
FROM debian:stable-slim
ENV RUST_BACKTRACE=1
WORKDIR /app
COPY --from=builder /app/target/release/pass_manager .
CMD [ "./pass_manager" ]

View File

@ -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()
}
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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

View File

@ -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");

View File

@ -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()));
};

View File

@ -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(())