err handling
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2024-12-14 22:07:38 +01:00
parent 151576df14
commit 4ede8e16e8
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263

View file

@ -8,6 +8,26 @@ use serde_json::json;
use sqlx::prelude::FromRow;
use std::path::PathBuf;
pub trait LogAndIgnore {
fn log_and_ignore(self, msg: &str);
}
impl<T, E: std::fmt::Debug> LogAndIgnore for Result<T, E> {
/// Handles the result by ignoring and logging it if it contains an error.
///
/// If the result is `Ok`, does nothing.
/// If the result is `Err(e)`
/// logs the message provided (`msg`) along with the error.
fn log_and_ignore(self, msg: &str) {
match self {
Ok(_) => {}
Err(e) => {
log::error!("{msg} : {:?}", e);
}
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct YouTubeMeta {
pub id: String,
@ -132,7 +152,7 @@ impl Video {
.bind(cat)
.execute(&mut *tx)
.await
.unwrap();
.log_and_ignore("Category mapping already exists");
}
if let Some(tags) = meta.tags() {
@ -142,7 +162,7 @@ impl Video {
.bind(&tag)
.execute(&mut *tx)
.await
.unwrap();
.log_and_ignore("YT Tag mapping already exists");
}
}