diff --git a/src/api/router/args.rs b/src/api/router/args.rs index b54a6f80..776ce4f4 100644 --- a/src/api/router/args.rs +++ b/src/api/router/args.rs @@ -2,11 +2,8 @@ use std::{mem, ops::Deref}; use axum::{async_trait, body::Body, extract::FromRequest}; use bytes::{BufMut, BytesMut}; -use conduit::{debug, debug_warn, trace, warn, Error, Result}; -use ruma::{ - api::{client::error::ErrorKind, IncomingRequest}, - CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId, -}; +use conduit::{debug, err, trace, Error, Result}; +use ruma::{api::IncomingRequest, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId}; use super::{auth, auth::Auth, request, request::Request}; use crate::{service::appservice::RegistrationInfo, services}; @@ -103,21 +100,14 @@ where let mut http_request = hyper::Request::builder() .uri(request.parts.uri.clone()) .method(request.parts.method.clone()); - *http_request.headers_mut().unwrap() = request.parts.headers.clone(); - let http_request = http_request.body(body).unwrap(); - debug!( - "{:?} {:?} {:?}", - http_request.method(), - http_request.uri(), - http_request.headers() - ); + *http_request.headers_mut().expect("mutable http headers") = request.parts.headers.clone(); + let http_request = http_request.body(body).expect("http request body"); - trace!("{:?} {:?} {:?}", http_request.method(), http_request.uri(), json_body); - let body = T::try_from_http_request(http_request, &request.path).map_err(|e| { - warn!("try_from_http_request failed: {e:?}",); - debug_warn!("JSON body: {:?}", json_body); - Error::BadRequest(ErrorKind::BadJson, "Failed to deserialize request.") - })?; + let headers = http_request.headers(); + let method = http_request.method(); + let uri = http_request.uri(); + debug!("{method:?} {uri:?} {headers:?}"); + trace!("{method:?} {uri:?} {json_body:?}"); - Ok(body) + T::try_from_http_request(http_request, &request.path).map_err(|e| err!(Request(BadJson(debug_warn!("{e}"))))) } diff --git a/src/api/router/request.rs b/src/api/router/request.rs index 56c76619..bed8d057 100644 --- a/src/api/router/request.rs +++ b/src/api/router/request.rs @@ -2,11 +2,11 @@ use std::str; use axum::{extract::Path, RequestExt, RequestPartsExt}; use bytes::Bytes; +use conduit::err; use http::request::Parts; -use ruma::api::client::error::ErrorKind; use serde::Deserialize; -use crate::{services, Error, Result}; +use crate::{services, Result}; #[derive(Deserialize)] pub(super) struct QueryParams { @@ -26,14 +26,15 @@ pub(super) async fn from(request: hyper::Request) -> Result> = parts.extract().await?; - let query = serde_html_form::from_str(parts.uri.query().unwrap_or_default()) - .map_err(|_| Error::BadRequest(ErrorKind::Unknown, "Failed to read query parameters"))?; + let query = parts.uri.query().unwrap_or_default(); + let query = + serde_html_form::from_str(query).map_err(|e| err!(Request(Unknown("Failed to read query parameters: {e}"))))?; let max_body_size = services().globals.config.max_request_size; let body = axum::body::to_bytes(body, max_body_size) .await - .map_err(|_| Error::BadRequest(ErrorKind::TooLarge, "Request body too large"))?; + .map_err(|e| err!(Request(TooLarge("Request body too large: {e}"))))?; Ok(Request { path, diff --git a/src/api/server/send.rs b/src/api/server/send.rs index 122f564f..31f8e73b 100644 --- a/src/api/server/send.rs +++ b/src/api/server/send.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeMap, net::IpAddr, time::Instant}; use axum_client_ip::InsecureClientIp; -use conduit::debug_warn; +use conduit::{debug, debug_warn, err, trace, warn, Err}; use ruma::{ api::{ client::error::ErrorKind, @@ -18,7 +18,6 @@ use ruma::{ OwnedEventId, ServerName, }; use tokio::sync::RwLock; -use tracing::{debug, error, trace, warn}; use crate::{ service::rooms::event_handler::parse_incoming_pdu, @@ -39,24 +38,17 @@ pub(crate) async fn send_transaction_message_route( let origin = body.origin.as_ref().expect("server is authenticated"); if *origin != body.body.origin { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "Not allowed to send transactions on behalf of other servers", - )); + return Err!(Request(Forbidden( + "Not allowed to send transactions on behalf of other servers" + ))); } if body.pdus.len() > 50_usize { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "Not allowed to send more than 50 PDUs in one transaction", - )); + return Err!(Request(Forbidden("Not allowed to send more than 50 PDUs in one transaction"))); } if body.edus.len() > 100_usize { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "Not allowed to send more than 100 EDUs in one transaction", - )); + return Err!(Request(Forbidden("Not allowed to send more than 100 EDUs in one transaction"))); } let txn_start_time = Instant::now(); @@ -392,10 +384,9 @@ async fn handle_edu_direct_to_device( target_user_id, target_device_id, &ev_type.to_string(), - event.deserialize_as().map_err(|e| { - error!("To-Device event is invalid: {event:?} {e}"); - Error::BadRequest(ErrorKind::InvalidParam, "Event is invalid") - })?, + event + .deserialize_as() + .map_err(|e| err!(Request(InvalidParam(error!("To-Device event is invalid: {e}")))))?, )?; }, @@ -408,7 +399,7 @@ async fn handle_edu_direct_to_device( &ev_type.to_string(), event .deserialize_as() - .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Event is invalid"))?, + .map_err(|e| err!(Request(InvalidParam("Event is invalid: {e}"))))?, )?; } }, diff --git a/src/core/error/err.rs b/src/core/error/err.rs index 66634f2b..55e38f18 100644 --- a/src/core/error/err.rs +++ b/src/core/error/err.rs @@ -31,6 +31,7 @@ //! Err(Database(error!("problem with db: {msg}")))` logs the error at the //! callsite and then returns the error with the same string. Caller has the //! option of replacing `error!` with `debug_error!`. + #[macro_export] macro_rules! Err { ($($args:tt)*) => { diff --git a/src/core/error/mod.rs b/src/core/error/mod.rs index 1f0d56c1..9439261e 100644 --- a/src/core/error/mod.rs +++ b/src/core/error/mod.rs @@ -78,7 +78,7 @@ pub enum Error { // conduwuit #[error("Arithmetic operation failed: {0}")] - Arithmetic(&'static str), + Arithmetic(Cow<'static, str>), #[error("There was a problem with the '{0}' directive in your configuration: {1}")] Config(&'static str, Cow<'static, str>), #[error("{0}")] diff --git a/src/core/utils/math.rs b/src/core/utils/math.rs index 155721e7..96ac6dc2 100644 --- a/src/core/utils/math.rs +++ b/src/core/utils/math.rs @@ -2,14 +2,14 @@ use std::{cmp, time::Duration}; pub use checked_ops::checked_ops; -use crate::{Error, Result}; +use crate::{Err, Error, Result}; /// Checked arithmetic expression. Returns a Result #[macro_export] macro_rules! checked { ($($input:tt)*) => { $crate::utils::math::checked_ops!($($input)*) - .ok_or_else(|| $crate::Error::Arithmetic("operation overflowed or result invalid")) + .ok_or_else(|| $crate::err!(Arithmetic("operation overflowed or result invalid"))) } } @@ -21,7 +21,7 @@ macro_rules! validated { ($($input:tt)*) => { //#[allow(clippy::arithmetic_side_effects)] { //Some($($input)*) - // .ok_or_else(|| $crate::Error::Arithmetic("this error should never been seen")) + // .ok_or_else(|| $crate::err!(Arithmetic("this error should never been seen"))) //} //NOTE: remove me when stmt_expr_attributes is stable @@ -57,7 +57,7 @@ pub fn continue_exponential_backoff(min: Duration, max: Duration, elapsed: Durat #[allow(clippy::as_conversions)] pub fn usize_from_f64(val: f64) -> Result { if val < 0.0 { - return Err(Error::Arithmetic("Converting negative float to unsigned integer")); + return Err!(Arithmetic("Converting negative float to unsigned integer")); } //SAFETY: diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 41019cd1..f63ebf09 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -9,7 +9,7 @@ use std::{ }; use async_trait::async_trait; -use conduit::{debug, error, Error, Result}; +use conduit::{debug, error, error::default_log, Error, Result}; pub use create::create_admin_room; pub use grant::make_user_admin; use loole::{Receiver, Sender}; @@ -239,9 +239,9 @@ async fn respond_to_room(content: RoomMessageEventContent, room_id: &RoomId, use .build_and_append_pdu(response_pdu, user_id, room_id, &state_lock) .await { - if let Err(e) = handle_response_error(e, room_id, user_id, &state_lock).await { - error!("{e}"); - } + handle_response_error(e, room_id, user_id, &state_lock) + .await + .unwrap_or_else(default_log); } } diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index c969d1e8..1638235b 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -6,7 +6,7 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc, time::SystemTime}; use async_trait::async_trait; use base64::{engine::general_purpose, Engine as _}; -use conduit::{debug, debug_error, err, error, utils, Result, Server}; +use conduit::{debug, debug_error, err, error, utils, Err, Result, Server}; use data::{Data, Metadata}; use ruma::{OwnedMxcUri, OwnedUserId}; use serde::Serialize; @@ -100,10 +100,9 @@ impl Service { Ok(()) } else { - error!("Failed to find any media keys for MXC \"{mxc}\" in our database (MXC does not exist)"); - Err(Error::bad_database( - "Failed to find any media keys for the provided MXC in our database (MXC does not exist)", - )) + Err!(Database(error!( + "Failed to find any media keys for MXC {mxc:?} in our database." + ))) } } @@ -137,23 +136,16 @@ impl Service { let all_keys = self.db.get_all_media_keys(); let user_duration: SystemTime = match cyborgtime::parse_duration(&time) { - Ok(duration) => { - debug!("Parsed duration: {:?}", duration); - debug!("System time now: {:?}", SystemTime::now()); - SystemTime::now().checked_sub(duration).ok_or_else(|| { - Error::bad_database("Duration specified is not valid against the current system time") - })? - }, - Err(e) => { - error!("Failed to parse user-specified time duration: {}", e); - return Err(Error::bad_database("Failed to parse user-specified time duration.")); - }, + Err(e) => return Err!(Database(error!("Failed to parse specified time duration: {e}"))), + Ok(duration) => SystemTime::now() + .checked_sub(duration) + .ok_or(err!(Arithmetic("Duration {duration:?} is too large")))?, }; let mut remote_mxcs: Vec = vec![]; for key in all_keys { - debug!("Full MXC key from database: {:?}", key); + debug!("Full MXC key from database: {key:?}"); // we need to get the MXC URL from the first part of the key (the first 0xff / // 255 push). this is all necessary because of conduit using magic keys for @@ -162,24 +154,19 @@ impl Service { let mxc = parts .next() .map(|bytes| { - utils::string_from_bytes(bytes).map_err(|e| { - error!("Failed to parse MXC unicode bytes from our database: {}", e); - Error::bad_database("Failed to parse MXC unicode bytes from our database") - }) + utils::string_from_bytes(bytes) + .map_err(|e| err!(Database(error!("Failed to parse MXC unicode bytes from our database: {e}")))) }) .transpose()?; let Some(mxc_s) = mxc else { - return Err(Error::bad_database( - "Parsed MXC URL unicode bytes from database but still is None", - )); + return Err!(Database("Parsed MXC URL unicode bytes from database but still is None")); }; - debug!("Parsed MXC key to URL: {}", mxc_s); - + debug!("Parsed MXC key to URL: {mxc_s}"); let mxc = OwnedMxcUri::from(mxc_s); if mxc.server_name() == Ok(services().globals.server_name()) { - debug!("Ignoring local media MXC: {}", mxc); + debug!("Ignoring local media MXC: {mxc}"); // ignore our own MXC URLs as this would be local media. continue; } @@ -198,14 +185,14 @@ impl Service { }, Err(err) => { if force { - error!("Could not delete MXC path {:?}: {:?}. Skipping...", path, err); + error!("Could not delete MXC path {path:?}: {err:?}. Skipping..."); continue; } return Err(err.into()); }, }; - debug!("File created at: {:?}", file_created_at); + debug!("File created at: {file_created_at:?}"); if file_created_at <= user_duration { debug!("File is within user duration, pushing to list of file paths and keys to delete."); remote_mxcs.push(mxc.to_string()); @@ -215,15 +202,12 @@ impl Service { debug!( "Finished going through all our media in database for eligible keys to delete, checking if these are empty" ); - if remote_mxcs.is_empty() { - return Err(Error::bad_database("Did not found any eligible MXCs to delete.")); + return Err!(Database("Did not found any eligible MXCs to delete.")); } - debug!("Deleting media now in the past \"{:?}\".", user_duration); - + debug!("Deleting media now in the past {user_duration:?}."); let mut deletion_count: usize = 0; - for mxc in remote_mxcs { debug!("Deleting MXC {mxc} from database and filesystem"); self.delete(&mxc).await?; diff --git a/src/service/users/data.rs b/src/service/users/data.rs index 302eae9d..5546adb1 100644 --- a/src/service/users/data.rs +++ b/src/service/users/data.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, mem::size_of, sync::Arc}; -use conduit::{debug_info, utils, warn, Error, Result}; +use conduit::{debug_info, err, utils, warn, Err, Error, Result}; use database::{Database, Map}; use ruma::{ api::client::{device::Device, error::ErrorKind, filter::FilterDefinition}, @@ -87,19 +87,19 @@ impl Data { let mut parts = bytes.split(|&b| b == 0xFF); let user_bytes = parts .next() - .ok_or_else(|| Error::bad_database("User ID in token_userdeviceid is invalid."))?; + .ok_or_else(|| err!(Database("User ID in token_userdeviceid is invalid.")))?; let device_bytes = parts .next() - .ok_or_else(|| Error::bad_database("Device ID in token_userdeviceid is invalid."))?; + .ok_or_else(|| err!(Database("Device ID in token_userdeviceid is invalid.")))?; Ok(Some(( UserId::parse( utils::string_from_bytes(user_bytes) - .map_err(|_| Error::bad_database("User ID in token_userdeviceid is invalid unicode."))?, + .map_err(|e| err!(Database("User ID in token_userdeviceid is invalid unicode. {e}")))?, ) - .map_err(|_| Error::bad_database("User ID in token_userdeviceid is invalid."))?, + .map_err(|e| err!(Database("User ID in token_userdeviceid is invalid. {e}")))?, utils::string_from_bytes(device_bytes) - .map_err(|_| Error::bad_database("Device ID in token_userdeviceid is invalid."))?, + .map_err(|e| err!(Database("Device ID in token_userdeviceid is invalid. {e}")))?, ))) }) } @@ -109,9 +109,9 @@ impl Data { Box::new(self.userid_password.iter().map(|(bytes, _)| { UserId::parse( utils::string_from_bytes(&bytes) - .map_err(|_| Error::bad_database("User ID in userid_password is invalid unicode."))?, + .map_err(|e| err!(Database("User ID in userid_password is invalid unicode. {e}")))?, ) - .map_err(|_| Error::bad_database("User ID in userid_password is invalid.")) + .map_err(|e| err!(Database("User ID in userid_password is invalid. {e}"))) })) } @@ -165,7 +165,7 @@ impl Data { .map_or(Ok(None), |bytes| { Ok(Some( utils::string_from_bytes(&bytes) - .map_err(|_| Error::bad_database("Displayname in db is invalid."))?, + .map_err(|e| err!(Database("Displayname in db is invalid. {e}")))?, )) }) } @@ -188,10 +188,8 @@ impl Data { self.userid_avatarurl .get(user_id.as_bytes())? .map(|bytes| { - let s_bytes = utils::string_from_bytes(&bytes).map_err(|e| { - warn!("Avatar URL in db is invalid: {}", e); - Error::bad_database("Avatar URL in db is invalid.") - })?; + let s_bytes = utils::string_from_bytes(&bytes) + .map_err(|e| err!(Database(warn!("Avatar URL in db is invalid: {e}"))))?; let mxc_uri: OwnedMxcUri = s_bytes.into(); Ok(mxc_uri) }) @@ -215,10 +213,7 @@ impl Data { self.userid_blurhash .get(user_id.as_bytes())? .map(|bytes| { - let s = utils::string_from_bytes(&bytes) - .map_err(|_| Error::bad_database("Avatar URL in db is invalid."))?; - - Ok(s) + utils::string_from_bytes(&bytes).map_err(|e| err!(Database("Avatar URL in db is invalid. {e}"))) }) .transpose() } @@ -314,9 +309,9 @@ impl Data { bytes .rsplit(|&b| b == 0xFF) .next() - .ok_or_else(|| Error::bad_database("UserDevice ID in db is invalid."))?, + .ok_or_else(|| err!(Database("UserDevice ID in db is invalid.")))?, ) - .map_err(|_| Error::bad_database("Device ID in userdeviceid_metadata is invalid."))? + .map_err(|e| err!(Database("Device ID in userdeviceid_metadata is invalid. {e}")))? .into()) }), ) @@ -330,13 +325,9 @@ impl Data { // should not be None, but we shouldn't assert either lol... if self.userdeviceid_metadata.get(&userdeviceid)?.is_none() { - warn!( - "Called set_token for a non-existent user \"{}\" and/or device ID \"{}\" with no metadata in database", - user_id, device_id - ); - return Err(Error::bad_database( - "User does not exist or device ID has no metadata in database.", - )); + return Err!(Database(error!( + "User {user_id:?} does not exist or device ID {device_id:?} has no metadata." + ))); } // Remove old token @@ -366,14 +357,9 @@ impl Data { // Only existing devices should be able to call this, but we shouldn't assert // either... if self.userdeviceid_metadata.get(&key)?.is_none() { - warn!( - "Called add_one_time_key for a non-existent user \"{}\" and/or device ID \"{}\" with no metadata in \ - database", - user_id, device_id - ); - return Err(Error::bad_database( - "User does not exist or device ID has no metadata in database.", - )); + return Err!(Database(error!( + "User {user_id:?} does not exist or device ID {device_id:?} has no metadata." + ))); } key.push(0xFF); @@ -401,7 +387,7 @@ impl Data { .get(user_id.as_bytes())? .map_or(Ok(0), |bytes| { utils::u64_from_bytes(&bytes) - .map_err(|_| Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.")) + .map_err(|e| err!(Database("Count in roomid_lastroomactiveupdate is invalid. {e}"))) }) } @@ -429,11 +415,10 @@ impl Data { serde_json::from_slice( key.rsplit(|&b| b == 0xFF) .next() - .ok_or_else(|| Error::bad_database("OneTimeKeyId in db is invalid."))?, + .ok_or_else(|| err!(Database("OneTimeKeyId in db is invalid.")))?, ) - .map_err(|_| Error::bad_database("OneTimeKeyId in db is invalid."))?, - serde_json::from_slice(&value) - .map_err(|_| Error::bad_database("OneTimeKeys in db are invalid."))?, + .map_err(|e| err!(Database("OneTimeKeyId in db is invalid. {e}")))?, + serde_json::from_slice(&value).map_err(|e| err!(Database("OneTimeKeys in db are invalid. {e}")))?, )) }) .transpose() @@ -457,9 +442,9 @@ impl Data { bytes .rsplit(|&b| b == 0xFF) .next() - .ok_or_else(|| Error::bad_database("OneTimeKey ID in db is invalid."))?, + .ok_or_else(|| err!(Database("OneTimeKey ID in db is invalid.")))?, ) - .map_err(|_| Error::bad_database("DeviceKeyId in db is invalid."))? + .map_err(|e| err!(Database("DeviceKeyId in db is invalid. {e}")))? .algorithm(), ) }) { @@ -581,19 +566,19 @@ impl Data { .get(&key)? .ok_or(Error::BadRequest(ErrorKind::InvalidParam, "Tried to sign nonexistent key."))?, ) - .map_err(|_| Error::bad_database("key in keyid_key is invalid."))?; + .map_err(|e| err!(Database("key in keyid_key is invalid. {e}")))?; let signatures = cross_signing_key .get_mut("signatures") - .ok_or_else(|| Error::bad_database("key in keyid_key has no signatures field."))? + .ok_or_else(|| err!(Database("key in keyid_key has no signatures field.")))? .as_object_mut() - .ok_or_else(|| Error::bad_database("key in keyid_key has invalid signatures field."))? + .ok_or_else(|| err!(Database("key in keyid_key has invalid signatures field.")))? .entry(sender_id.to_string()) .or_insert_with(|| serde_json::Map::new().into()); signatures .as_object_mut() - .ok_or_else(|| Error::bad_database("signatures in keyid_key for a user is invalid."))? + .ok_or_else(|| err!(Database("signatures in keyid_key for a user is invalid.")))? .insert(signature.0, signature.1.into()); self.keyid_key.insert( @@ -640,7 +625,7 @@ impl Data { Error::bad_database("User ID in devicekeychangeid_userid is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("User ID in devicekeychangeid_userid is invalid.")) + .map_err(|e| err!(Database("User ID in devicekeychangeid_userid is invalid. {e}"))) }), ) } @@ -685,7 +670,7 @@ impl Data { self.keyid_key.get(&key)?.map_or(Ok(None), |bytes| { Ok(Some( - serde_json::from_slice(&bytes).map_err(|_| Error::bad_database("DeviceKeys in db are invalid."))?, + serde_json::from_slice(&bytes).map_err(|e| err!(Database("DeviceKeys in db are invalid. {e}")))?, )) }) } @@ -719,7 +704,7 @@ impl Data { ) -> Result>> { self.keyid_key.get(key)?.map_or(Ok(None), |bytes| { let mut cross_signing_key = serde_json::from_slice::(&bytes) - .map_err(|_| Error::bad_database("CrossSigningKey in db is invalid."))?; + .map_err(|e| err!(Database("CrossSigningKey in db is invalid. {e}")))?; clean_signatures(&mut cross_signing_key, sender_user, user_id, allowed_signatures)?; Ok(Some(Raw::from_json( @@ -751,7 +736,7 @@ impl Data { self.keyid_key.get(&key)?.map_or(Ok(None), |bytes| { Ok(Some( serde_json::from_slice(&bytes) - .map_err(|_| Error::bad_database("CrossSigningKey in db is invalid."))?, + .map_err(|e| err!(Database("CrossSigningKey in db is invalid. {e}")))?, )) }) }) @@ -792,7 +777,7 @@ impl Data { for (_, value) in self.todeviceid_events.scan_prefix(prefix) { events.push( serde_json::from_slice(&value) - .map_err(|_| Error::bad_database("Event in todeviceid_events is invalid."))?, + .map_err(|e| err!(Database("Event in todeviceid_events is invalid. {e}")))?, ); } @@ -816,7 +801,7 @@ impl Data { Ok::<_, Error>(( key.clone(), utils::u64_from_bytes(&key[key.len().saturating_sub(size_of::())..key.len()]) - .map_err(|_| Error::bad_database("ToDeviceId has invalid count bytes."))?, + .map_err(|e| err!(Database("ToDeviceId has invalid count bytes. {e}")))?, )) }) .filter_map(Result::ok) @@ -877,7 +862,7 @@ impl Data { .get(user_id.as_bytes())? .map_or(Ok(None), |bytes| { utils::u64_from_bytes(&bytes) - .map_err(|_| Error::bad_database("Invalid devicelistversion in db.")) + .map_err(|e| err!(Database("Invalid devicelistversion in db. {e}"))) .map(Some) }) } @@ -893,7 +878,7 @@ impl Data { .scan_prefix(key) .map(|(_, bytes)| { serde_json::from_slice::(&bytes) - .map_err(|_| Error::bad_database("Device in userdeviceid_metadata is invalid.")) + .map_err(|e| err!(Database("Device in userdeviceid_metadata is invalid. {e}"))) }), ) } @@ -920,7 +905,7 @@ impl Data { let raw = self.userfilterid_filter.get(&key)?; if let Some(raw) = raw { - serde_json::from_slice(&raw).map_err(|_| Error::bad_database("Invalid filter event in db.")) + serde_json::from_slice(&raw).map_err(|e| err!(Database("Invalid filter event in db. {e}"))) } else { Ok(None) } @@ -954,7 +939,7 @@ impl Data { let expires_at = u64::from_be_bytes( expires_at_bytes .try_into() - .map_err(|_| Error::bad_database("expires_at in openid_userid is invalid u64."))?, + .map_err(|e| err!(Database("expires_at in openid_userid is invalid u64. {e}")))?, ); if expires_at < utils::millis_since_unix_epoch() { @@ -966,9 +951,9 @@ impl Data { UserId::parse( utils::string_from_bytes(user_bytes) - .map_err(|_| Error::bad_database("User ID in openid_userid is invalid unicode."))?, + .map_err(|e| err!(Database("User ID in openid_userid is invalid unicode. {e}")))?, ) - .map_err(|_| Error::bad_database("User ID in openid_userid is invalid.")) + .map_err(|e| err!(Database("User ID in openid_userid is invalid. {e}"))) } }