From 95eaa9596c66b5bfe2e312100b1f3b559e8ca8f9 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 22 Mar 2024 17:43:30 +0100 Subject: [PATCH] feat: added simpler ways to ignore+log errors --- src/errors.rs | 25 +++++++++++++++++++++++++ src/main.rs | 1 + 2 files changed, 26 insertions(+) create mode 100644 src/errors.rs diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..6e62053 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,25 @@ +pub trait LoggableError { + fn info_failed(self, msg: &str); + fn warn_failed(self, msg: &str); + fn err_failed(self, msg: &str); +} + +impl LoggableError for Result { + fn info_failed(self, msg: &str) { + if let Err(e) = self { + tracing::info!("{} : {}", msg, e); + } + } + + fn warn_failed(self, msg: &str) { + if let Err(e) = self { + tracing::warn!("{} : {}", msg, e); + } + } + + fn err_failed(self, msg: &str) { + if let Err(e) = self { + tracing::error!("{} : {}", msg, e); + } + } +} diff --git a/src/main.rs b/src/main.rs index d9e940f..e132a0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ pub mod migrations; pub mod activitystream; pub mod activitypub; pub mod server; +pub mod errors; use clap::{Parser, Subcommand}; use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel};