From 035d27724df9c96af4634e61cae4320df8a45b3f Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 13:58:16 +0100 Subject: [PATCH 1/2] fix(auth): logs keep the cause of rejected uploads, delivery transport failures and unusable signing keys - The picture upload and pasted verification link logs format their error through ErrorChain, as the rest of auth does. - An outbound request that gets no response logs its reqwest error, without its URL, before it is reduced to the failure the delivery records. - The dashboard logs why a stored signing key cannot be used; its answer is unchanged. --- apps/auth-service/src/admin/error.rs | 12 ++++++--- apps/auth-service/src/deliveries/outbound.rs | 25 ++++++++++++------- apps/auth-service/src/web/settings/emails.rs | 5 +++- apps/auth-service/src/web/settings/profile.rs | 5 ++-- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/apps/auth-service/src/admin/error.rs b/apps/auth-service/src/admin/error.rs index e717e2a28..85dcb9a5e 100644 --- a/apps/auth-service/src/admin/error.rs +++ b/apps/auth-service/src/admin/error.rs @@ -351,10 +351,16 @@ impl From for ApiError { | AdminError::HandleReserved | AdminError::AnnouncementSent | AdminError::AnnouncementChanged + | AdminError::SigningKey(KeyError::Mismatched(_) | KeyError::NoActiveKey) => { + Self::conflict(message) + } // A stored key that cannot sign is refused, and the form says which. - | AdminError::SigningKey( - KeyError::Stored { .. } | KeyError::Mismatched(_) | KeyError::NoActiveKey, - ) => Self::conflict(message), + // Why it cannot, such as a key-encryption key no longer accepted, is + // only for the log. + error @ AdminError::SigningKey(KeyError::Stored { .. }) => { + Self::log_error(&error); + Self::conflict(message) + } AdminError::Database(error) | AdminError::SigningKey(KeyError::Database(error)) => { error.into() } diff --git a/apps/auth-service/src/deliveries/outbound.rs b/apps/auth-service/src/deliveries/outbound.rs index cefe2b1bb..3efb5114f 100644 --- a/apps/auth-service/src/deliveries/outbound.rs +++ b/apps/auth-service/src/deliveries/outbound.rs @@ -13,7 +13,7 @@ use reqwest::{ dns::{Addrs, Name, Resolve, Resolving}, redirect, }; -use sourceorigin_common::net::PublicAddress; +use sourceorigin_common::{ErrorChain, net::PublicAddress}; use sourceorigin_telemetry::SendTraced; use std::{ error::Error as StdError, @@ -124,10 +124,7 @@ impl OutboundClient { .await?; let mut body = Vec::new(); while body.len() < limit - && let Some(chunk) = response - .chunk() - .await - .map_err(|error| Self::transport_error(&error))? + && let Some(chunk) = response.chunk().await.map_err(Self::transport_error)? { let room = limit - body.len(); body.extend_from_slice(&chunk[..chunk.len().min(room)]); @@ -146,7 +143,7 @@ impl OutboundClient { let response = request(self.client.request(method, url)) .send_traced() .await - .map_err(|error| Self::transport_error(&error))?; + .map_err(Self::transport_error)?; Self::check_status(response.status(), response.headers(), Utc::now())?; Ok(response) } @@ -169,9 +166,19 @@ impl OutboundClient { Ok(url) } - /// Classifies a request that got no response. A refused address is found in - /// the error's sources, where the resolver's error ends up. - fn transport_error(error: &reqwest::Error) -> DeliveryError { + /// Classifies a request that got no response, and logs why as a warning: the + /// classification alone becomes the delivery's `last_error`. A refused address + /// is found in the error's sources, where the resolver's error ends up. + fn transport_error(error: reqwest::Error) -> DeliveryError { + let classified = Self::classify(&error); + // The URL can name a person, as a provider's picture URL does. + let error = error.without_url(); + tracing::warn!(error = %ErrorChain(&error), failure = %classified, "outbound request got no response"); + classified + } + + /// The failure [`Self::transport_error`] reports for `error`. + fn classify(error: &reqwest::Error) -> DeliveryError { let mut source: Option<&(dyn StdError + 'static)> = Some(error); while let Some(current) = source { if let Some(refused) = current.downcast_ref::() { diff --git a/apps/auth-service/src/web/settings/emails.rs b/apps/auth-service/src/web/settings/emails.rs index 5df29e843..961b67483 100644 --- a/apps/auth-service/src/web/settings/emails.rs +++ b/apps/auth-service/src/web/settings/emails.rs @@ -10,6 +10,7 @@ use crate::{ }, }; use serde::Deserialize; +use sourceorigin_common::ErrorChain; use sourceorigin_ui::{ Audience, EmailChange, EmailRow, EmailsState, Messages, Notice, Section, Tab, Title, }; @@ -46,7 +47,9 @@ impl Verification { Self::Link { link } => link, }; let token = Url::parse(link.trim()) - .inspect_err(|error| tracing::debug!(%error, "pasted verification link rejected")) + .inspect_err(|error| { + tracing::debug!(error = %ErrorChain(error), "pasted verification link rejected"); + }) .ok() .and_then(|link| { form_urlencoded::parse(link.fragment()?.as_bytes()) diff --git a/apps/auth-service/src/web/settings/profile.rs b/apps/auth-service/src/web/settings/profile.rs index 047a3e98b..f1a6452e8 100644 --- a/apps/auth-service/src/web/settings/profile.rs +++ b/apps/auth-service/src/web/settings/profile.rs @@ -11,6 +11,7 @@ use crate::{ }, }; use serde::Deserialize; +use sourceorigin_common::ErrorChain; use sourceorigin_ui::{ Audience, CROP_SIZE, CROP_X, CROP_Y, Messages, Notice, PICTURE_FIELD, ProfileChange, ProfileDialog, ProfileState, Section, Tab, Who, @@ -85,7 +86,7 @@ impl Profile { return Some(ProfileEdit::Oversize); } Err(error) => { - tracing::debug!(%error, "picture upload rejected"); + tracing::debug!(error = %ErrorChain(&*error), "picture upload rejected"); return None; } }; @@ -103,7 +104,7 @@ impl Profile { return Some(ProfileEdit::Oversize); } Err(error) => { - tracing::debug!(%error, "picture upload rejected"); + tracing::debug!(error = %ErrorChain(&*error), "picture upload rejected"); return None; } } From 06374fe1ceb4728c9af15bf118990730ebc26038 Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 15:13:15 +0100 Subject: [PATCH 2/2] fix(auth): an outbound failure's cause is a warning only for deliveries Review follow-up: the log reads "outbound request failed", since a body read can fail too. A back-channel delivery logs the cause as a warning beside its worker's; a picture import logs it at debug, since its caller already warns. --- apps/auth-service/src/deliveries/outbound.rs | 51 ++++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/apps/auth-service/src/deliveries/outbound.rs b/apps/auth-service/src/deliveries/outbound.rs index 3efb5114f..2450c292c 100644 --- a/apps/auth-service/src/deliveries/outbound.rs +++ b/apps/auth-service/src/deliveries/outbound.rs @@ -22,6 +22,7 @@ use std::{ time::Duration, }; use thiserror::Error; +use tracing::Level; use url::{Host, Url}; /// The longest connecting to a destination may take. @@ -100,7 +101,11 @@ impl OutboundClient { destination: &str, request: impl FnOnce(RequestBuilder) -> RequestBuilder, ) -> Result<(), DeliveryError> { - self.request(method, destination, request).await.map(drop) + // A delivery's worker logs only the failure, so the cause is a warning + // beside it. + self.request(method, destination, request, Level::WARN) + .await + .map(drop) } /// Fetches `destination` with `GET`, as [`Self::send`] sends, asking for the @@ -117,14 +122,22 @@ impl OutboundClient { accept: &str, limit: usize, ) -> Result, DeliveryError> { + // The caller warns of the failure, so the cause is only for debugging. + let cause = Level::DEBUG; let mut response = self - .request(Method::GET, destination, |request| { - request.header(ACCEPT, accept) - }) + .request( + Method::GET, + destination, + |request| request.header(ACCEPT, accept), + cause, + ) .await?; let mut body = Vec::new(); while body.len() < limit - && let Some(chunk) = response.chunk().await.map_err(Self::transport_error)? + && let Some(chunk) = response + .chunk() + .await + .map_err(|error| Self::transport_error(error, cause))? { let room = limit - body.len(); body.extend_from_slice(&chunk[..chunk.len().min(room)]); @@ -132,18 +145,20 @@ impl OutboundClient { Ok(body) } - /// [`Self::send`], returning the successful response with its body unread. + /// [`Self::send`], returning the successful response with its body unread, + /// and logging a transport failure's cause at `cause`. async fn request( &self, method: Method, destination: &str, request: impl FnOnce(RequestBuilder) -> RequestBuilder, + cause: Level, ) -> Result { let url = self.check(destination)?; let response = request(self.client.request(method, url)) .send_traced() .await - .map_err(Self::transport_error)?; + .map_err(|error| Self::transport_error(error, cause))?; Self::check_status(response.status(), response.headers(), Utc::now())?; Ok(response) } @@ -166,18 +181,24 @@ impl OutboundClient { Ok(url) } - /// Classifies a request that got no response, and logs why as a warning: the - /// classification alone becomes the delivery's `last_error`. A refused address - /// is found in the error's sources, where the resolver's error ends up. - fn transport_error(error: reqwest::Error) -> DeliveryError { - let classified = Self::classify(&error); + /// Classifies a request that failed in transport, before or while its + /// response arrived, and logs why at `level` (`WARN` or `DEBUG`): the + /// classification alone becomes the delivery's `last_error`. + fn transport_error(error: reqwest::Error, level: Level) -> DeliveryError { + let failure = Self::classify(&error); // The URL can name a person, as a provider's picture URL does. let error = error.without_url(); - tracing::warn!(error = %ErrorChain(&error), failure = %classified, "outbound request got no response"); - classified + let error = ErrorChain(&error); + if level == Level::WARN { + tracing::warn!(%error, %failure, "outbound request failed"); + } else { + tracing::debug!(%error, %failure, "outbound request failed"); + } + failure } - /// The failure [`Self::transport_error`] reports for `error`. + /// The failure [`Self::transport_error`] reports for `error`. A refused + /// address is found in the error's sources, where the resolver's error ends up. fn classify(error: &reqwest::Error) -> DeliveryError { let mut source: Option<&(dyn StdError + 'static)> = Some(error); while let Some(current) = source {