feat: added simpler ways to ignore+log errors

This commit is contained in:
əlemi 2024-03-22 17:43:30 +01:00
parent 0ec636a868
commit 95eaa9596c
2 changed files with 26 additions and 0 deletions

25
src/errors.rs Normal file
View file

@ -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<T, E: std::error::Error> LoggableError for Result<T, E> {
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);
}
}
}

View file

@ -3,6 +3,7 @@ pub mod migrations;
pub mod activitystream; pub mod activitystream;
pub mod activitypub; pub mod activitypub;
pub mod server; pub mod server;
pub mod errors;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel}; use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel};