improved logging of errors in from_user fn

This commit is contained in:
jude 2020-10-13 13:48:47 +01:00
parent b2111616e8
commit c8ab8e66e3

View File

@ -10,6 +10,8 @@ use sqlx::{Cursor, MySqlPool, Row};
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use chrono_tz::Tz; use chrono_tz::Tz;
use log::error;
use crate::consts::{LOCAL_LANGUAGE, PREFIX, STRINGS_TABLE}; use crate::consts::{LOCAL_LANGUAGE, PREFIX, STRINGS_TABLE};
pub struct GuildData { pub struct GuildData {
@ -188,7 +190,7 @@ impl UserData {
) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> { ) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
let user_id = user.id.as_u64().to_owned(); let user_id = user.id.as_u64().to_owned();
if let Ok(c) = sqlx::query_as_unchecked!( match sqlx::query_as_unchecked!(
Self, Self,
" "
SELECT id, user, name, dm_channel, language, timezone FROM users WHERE user = ? SELECT id, user, name, dm_channel, language, timezone FROM users WHERE user = ?
@ -198,8 +200,9 @@ SELECT id, user, name, dm_channel, language, timezone FROM users WHERE user = ?
.fetch_one(pool) .fetch_one(pool)
.await .await
{ {
Ok(c) Ok(c) => Ok(c),
} else {
Err(sqlx::Error::RowNotFound) => {
let dm_channel = user.create_dm_channel(ctx).await?; let dm_channel = user.create_dm_channel(ctx).await?;
let dm_id = dm_channel.id.as_u64().to_owned(); let dm_id = dm_channel.id.as_u64().to_owned();
@ -231,6 +234,9 @@ SELECT id, user, name, dm_channel, language, timezone FROM users WHERE user = ?
.fetch_one(pool) .fetch_one(pool)
.await?) .await?)
} }
Err(e) => error!("Error querying for user: {:?}", e),
}
} }
pub async fn commit_changes(&self, pool: &MySqlPool) { pub async fn commit_changes(&self, pool: &MySqlPool) {