diff --git a/crates/crates_io_docs_rs/src/lib.rs b/crates/crates_io_docs_rs/src/lib.rs index 402f1238132..fc8cd021aad 100644 --- a/crates/crates_io_docs_rs/src/lib.rs +++ b/crates/crates_io_docs_rs/src/lib.rs @@ -62,7 +62,7 @@ impl RealDocsRsClient { Ok(Some(url)) => url, Ok(None) => Url::parse(DEFAULT_BASE_URL).unwrap(), Err(err) => { - warn!("Failed to parse DOCS_RS_BASE_URL: {err}"); + warn!("Failed to parse DOCS_RS_BASE_URL: {err:#}"); return None; } }; diff --git a/crates/crates_io_fastly/src/lib.rs b/crates/crates_io_fastly/src/lib.rs index 396d7dde8f3..094f3fb2aaa 100644 --- a/crates/crates_io_fastly/src/lib.rs +++ b/crates/crates_io_fastly/src/lib.rs @@ -17,13 +17,8 @@ pub enum Error { #[error("Invalid API token format")] InvalidApiToken(#[from] InvalidHeaderValue), - #[error("Failed to `POST {url}`{}: {source}", status.map(|s| format!(" (status: {})", s)).unwrap_or_default())] - PurgeFailed { - url: String, - status: Option, - #[source] - source: reqwest::Error, - }, + #[error("Failed to purge Fastly cache")] + PurgeFailed(#[source] reqwest::Error), } #[derive(Debug)] @@ -115,11 +110,7 @@ impl Fastly { .header("Fastly-Key", self.token_header_value()?) .send() .await - .map_err(|source| Error::PurgeFailed { - url: url.clone(), - status: None, - source, - })?; + .map_err(Error::PurgeFailed)?; let status = response.status(); @@ -138,11 +129,7 @@ impl Fastly { "invalidation request to Fastly failed" ); - Err(Error::PurgeFailed { - url, - status: Some(status), - source: error, - }) + Err(Error::PurgeFailed(error)) } } } @@ -267,10 +254,8 @@ mod tests { std::assert_matches!( result, - Err(Error::PurgeFailed { - status: Some(reqwest::StatusCode::SERVICE_UNAVAILABLE), - .. - }) + Err(Error::PurgeFailed(source)) + if source.status() == Some(reqwest::StatusCode::SERVICE_UNAVAILABLE) ); } } diff --git a/crates/crates_io_tarball/examples/check_all_crates.rs b/crates/crates_io_tarball/examples/check_all_crates.rs index 8c3941a69a5..de39439beed 100644 --- a/crates/crates_io_tarball/examples/check_all_crates.rs +++ b/crates/crates_io_tarball/examples/check_all_crates.rs @@ -87,7 +87,9 @@ async fn process_path(path: &Path, pb: &ProgressBar) { pb.suspend(|| match result { Ok(result) => debug!(%pkg_name, path = %path.display(), ?result), Err(error) => { - warn!(%pkg_name, path = %path.display(), "Failed to process tarball: {error}") + // Convert to anyhow so `{error:#}` includes the source chain. + let error = anyhow::Error::new(error); + warn!(%pkg_name, path = %path.display(), "Failed to process tarball: {error:#}") } }) } diff --git a/crates/crates_io_worker/src/worker.rs b/crates/crates_io_worker/src/worker.rs index c930791ddbd..b16af6d7d55 100644 --- a/crates/crates_io_worker/src/worker.rs +++ b/crates/crates_io_worker/src/worker.rs @@ -54,7 +54,7 @@ impl Worker { } } Err(error) => { - error!("Failed to run job: {error}"); + error!("Failed to run job: {error:#}"); sleep(self.poll_interval).await; } } @@ -108,7 +108,7 @@ impl Worker { storage::delete_successful_job(conn, job_id).await? } Err(error) => { - warn!("Failed to run job: {error}"); + warn!("Failed to run job: {error:#}"); storage::update_failed_job(conn, job_id).await; } } diff --git a/src/bin/crates-io/background_worker.rs b/src/bin/crates-io/background_worker.rs index a596400d909..108ff110bab 100644 --- a/src/bin/crates-io/background_worker.rs +++ b/src/bin/crates-io/background_worker.rs @@ -132,7 +132,7 @@ pub fn run() -> anyhow::Result<()> { let ctx = ctx.clone(); move || { if let Err(err) = ctx.lock_index() { - warn!("Failed to clone index: {err}"); + warn!("Failed to clone index: {err:#}"); }; } }); diff --git a/src/controllers/github/secret_scanning.rs b/src/controllers/github/secret_scanning.rs index 5c65bbf19cc..e846c47d41b 100644 --- a/src/controllers/github/secret_scanning.rs +++ b/src/controllers/github/secret_scanning.rs @@ -166,7 +166,7 @@ async fn alert_revoke_token( let result = send_trustpub_notification_emails(&actual_crate_ids, alert, ctx, conn).await; if let Err(error) = result { warn!( - "Failed to send trusted publishing token exposure notifications for crates {actual_crate_ids:?}: {error}", + "Failed to send trusted publishing token exposure notifications for crates {actual_crate_ids:?}: {error:#}", ); } @@ -209,7 +209,7 @@ async fn alert_revoke_token( if let Err(error) = send_notification_email(&token, alert, ctx, conn).await { warn!( token_id = %token.id, user_id = %token.user_id, - "Failed to send email notification: {error}", + "Failed to send email notification: {error:#}", ) } diff --git a/src/controllers/krate/update.rs b/src/controllers/krate/update.rs index ab36a78e4ab..baa5bd1d081 100644 --- a/src/controllers/krate/update.rs +++ b/src/controllers/krate/update.rs @@ -142,7 +142,7 @@ async fn update_inner( }; if let Err(err) = email.send(ctx, email_address).await { - warn!("Failed to send trustpub_only notification to {email_address}: {err}"); + warn!("Failed to send trustpub_only notification to {email_address}: {err:#}"); } } } diff --git a/src/controllers/token.rs b/src/controllers/token.rs index fb4f0fd1386..2d51747de50 100644 --- a/src/controllers/token.rs +++ b/src/controllers/token.rs @@ -229,7 +229,7 @@ pub async fn create_api_token( // email should not cause an error response to be returned to the // caller. if let Err(e) = send_creation_email(&ctx.emails, &recipient, context).await { - error!("Failed to send token creation email: {e}") + error!("Failed to send token creation email: {e:#}") } } diff --git a/src/controllers/trustpub/github_configs/create.rs b/src/controllers/trustpub/github_configs/create.rs index 9bb66569db8..db566c2b6d9 100644 --- a/src/controllers/trustpub/github_configs/create.rs +++ b/src/controllers/trustpub/github_configs/create.rs @@ -101,7 +101,7 @@ pub async fn create_trustpub_github_config( }; let gh_auth = encryption.decrypt(gh_auth).map_err(|err| { let login = &auth_user.gh_login; - warn!("Failed to decrypt GitHub token for user {login}: {err}"); + warn!("Failed to decrypt GitHub token for user {login}: {err:#}"); server_error("Internal server error") })?; let gh_auth = GitHubAuth::bearer(gh_auth); @@ -145,7 +145,7 @@ pub async fn create_trustpub_github_config( }; if let Err(err) = send_notification_email(&ctx, email_address, context).await { - warn!("Failed to send trusted publishing notification to {email_address}: {err}"); + warn!("Failed to send trusted publishing notification to {email_address}: {err:#}"); } } diff --git a/src/controllers/trustpub/github_configs/delete.rs b/src/controllers/trustpub/github_configs/delete.rs index f068181babf..7bd6860520d 100644 --- a/src/controllers/trustpub/github_configs/delete.rs +++ b/src/controllers/trustpub/github_configs/delete.rs @@ -93,7 +93,7 @@ pub async fn delete_trustpub_github_config( }; if let Err(err) = send_notification_email(&ctx, email_address, context).await { - warn!("Failed to send trusted publishing notification to {email_address}: {err}"); + warn!("Failed to send trusted publishing notification to {email_address}: {err:#}"); } } diff --git a/src/controllers/trustpub/gitlab_configs/create.rs b/src/controllers/trustpub/gitlab_configs/create.rs index 243bd2db9e4..f69faaa9547 100644 --- a/src/controllers/trustpub/gitlab_configs/create.rs +++ b/src/controllers/trustpub/gitlab_configs/create.rs @@ -118,7 +118,7 @@ pub async fn create_trustpub_gitlab_config( }; if let Err(err) = send_notification_email(&ctx, email_address, context).await { - warn!("Failed to send trusted publishing notification to {email_address}: {err}"); + warn!("Failed to send trusted publishing notification to {email_address}: {err:#}"); } } diff --git a/src/controllers/trustpub/gitlab_configs/delete.rs b/src/controllers/trustpub/gitlab_configs/delete.rs index cfa32930658..7996c2a0128 100644 --- a/src/controllers/trustpub/gitlab_configs/delete.rs +++ b/src/controllers/trustpub/gitlab_configs/delete.rs @@ -93,7 +93,7 @@ pub async fn delete_trustpub_gitlab_config( }; if let Err(err) = send_notification_email(&ctx, email_address, context).await { - warn!("Failed to send trusted publishing notification to {email_address}: {err}"); + warn!("Failed to send trusted publishing notification to {email_address}: {err:#}"); } } diff --git a/src/controllers/trustpub/tokens/exchange/mod.rs b/src/controllers/trustpub/tokens/exchange/mod.rs index 011b7844f2f..dd90ebf361b 100644 --- a/src/controllers/trustpub/tokens/exchange/mod.rs +++ b/src/controllers/trustpub/tokens/exchange/mod.rs @@ -58,7 +58,7 @@ pub async fn exchange_trustpub_token( return Err(bad_request("Invalid JWT key ID")); } Err(err) => { - warn!("Failed to load OIDC key set: {err}"); + warn!("Failed to load OIDC key set: {err:#}"); return Err(server_error("Failed to load OIDC key set")); } }; diff --git a/src/db.rs b/src/db.rs index 88775781e33..2cd8129195d 100644 --- a/src/db.rs +++ b/src/db.rs @@ -103,7 +103,11 @@ async fn establish_async_connection( let connector = MakeTlsConnector::new(connector); let result = tokio_postgres::connect(url, connector).await; - let (client, conn) = result.map_err(|err| BadConnection(err.to_string()))?; + let (client, conn) = result.map_err(|error| { + // Convert to anyhow so `{error:#}` includes the source chain. + let error = anyhow::Error::new(error); + BadConnection(format!("{error:#}")) + })?; AsyncPgConnection::try_from_client_and_connection(client, conn).await } diff --git a/src/metrics/collector.rs b/src/metrics/collector.rs index 0cab657ab96..bfa9ae2e7a8 100644 --- a/src/metrics/collector.rs +++ b/src/metrics/collector.rs @@ -22,7 +22,7 @@ pub fn spawn(deadpool: Pool, metrics: WorkerMetrics) { loop { if let Err(error) = record(&deadpool, &metrics, &mut observed_queues).await { - warn!("Failed to record service metrics: {error}"); + warn!("Failed to record service metrics: {error:#}"); } tokio::time::sleep(COLLECT_INTERVAL).await; diff --git a/src/sentry/mod.rs b/src/sentry/mod.rs index 5e59ba0e153..00f53e60d2e 100644 --- a/src/sentry/mod.rs +++ b/src/sentry/mod.rs @@ -19,7 +19,7 @@ pub fn init() -> Option { let config = match SentryConfig::from_environment() { Ok(config) => config, Err(error) => { - warn!("Failed to read Sentry configuration from environment: {error}"); + warn!("Failed to read Sentry configuration from environment: {error:#}"); return None; } }; diff --git a/src/util/errors.rs b/src/util/errors.rs index bb0231335a6..f720191de78 100644 --- a/src/util/errors.rs +++ b/src/util/errors.rs @@ -222,7 +222,7 @@ impl From for BoxedAppError { GitHub org memberships.", ), GitHubError::NotFound(_) => not_found(), - _ => internal(format!("didn't get a 200 result from github: {error}")), + _ => internal(format!("didn't get a 200 result from github: {error:#}")), } } } diff --git a/src/worker/jobs/docs_rs_queue_rebuild.rs b/src/worker/jobs/docs_rs_queue_rebuild.rs index e84677253d4..a1d3eb29452 100644 --- a/src/worker/jobs/docs_rs_queue_rebuild.rs +++ b/src/worker/jobs/docs_rs_queue_rebuild.rs @@ -43,7 +43,7 @@ impl BackgroundJob for DocsRsQueueRebuild { error!( name = self.name, version = self.version, - "couldn't queue docs rebuild. won't retry: {err}" + "couldn't queue docs rebuild. won't retry: {err:#}" ); Ok(()) } diff --git a/src/worker/jobs/dump_db.rs b/src/worker/jobs/dump_db.rs index b1c2a433f59..a70d11329fa 100644 --- a/src/worker/jobs/dump_db.rs +++ b/src/worker/jobs/dump_db.rs @@ -73,7 +73,7 @@ impl BackgroundJob for DumpDb { let dist = CloudFrontDistribution::Static; if let Err(error) = ctx.invalidate_cdns(&conn, dist, &tar_key.cdn_path()).await { - warn!("Failed to invalidate CDN caches: {error}"); + warn!("Failed to invalidate CDN caches: {error:#}"); } info!("Uploading zip file…"); @@ -88,7 +88,7 @@ impl BackgroundJob for DumpDb { info!("Invalidating CDN caches…"); if let Err(error) = ctx.invalidate_cdns(&conn, dist, &zip_key.cdn_path()).await { - warn!("Failed to invalidate CDN caches: {error}"); + warn!("Failed to invalidate CDN caches: {error:#}"); } Ok(()) diff --git a/src/worker/jobs/generate_og_image.rs b/src/worker/jobs/generate_og_image.rs index 14ba2bb4fe1..a7788b9407d 100644 --- a/src/worker/jobs/generate_og_image.rs +++ b/src/worker/jobs/generate_og_image.rs @@ -109,7 +109,9 @@ impl BackgroundJob for GenerateOgImage { && let Some(cdn_domain) = &ctx.config.storage.cdn_prefix && let Err(error) = fastly.purge_both_domains(cdn_domain, &og_image_path).await { - warn!("Failed to invalidate Fastly CDN for {crate_name}: {error}"); + // Convert to anyhow so `{error:#}` includes the source chain. + let error = anyhow::Error::new(error); + warn!("Failed to invalidate Fastly CDN for {crate_name}: {error:#}"); } info!("CDN invalidation completed for crate {crate_name}"); diff --git a/src/worker/jobs/index/sync.rs b/src/worker/jobs/index/sync.rs index 8e0c76957b2..cca66c7ef91 100644 --- a/src/worker/jobs/index/sync.rs +++ b/src/worker/jobs/index/sync.rs @@ -202,9 +202,11 @@ impl BackgroundJob for SyncToSparseIndex { for domain in domains { if let Err(error) = fastly.purge(&domain, &path).await { + // Convert to anyhow so `{error:#}` includes the source chain. + let error = anyhow::Error::new(error); warn!( domain, - path, "Failed to invalidate sparse index on Fastly: {error}" + path, "Failed to invalidate sparse index on Fastly: {error:#}" ); } } diff --git a/src/worker/jobs/index_version_downloads_archive/mod.rs b/src/worker/jobs/index_version_downloads_archive/mod.rs index 910872f9cae..7dec943e48f 100644 --- a/src/worker/jobs/index_version_downloads_archive/mod.rs +++ b/src/worker/jobs/index_version_downloads_archive/mod.rs @@ -60,12 +60,12 @@ impl BackgroundJob for IndexVersionDownloadsArchive { let result = ctx.invalidate_cdns(&conn, dist, INDEX_PATH).await; if let Err(error) = result { - warn!("Failed to invalidate CDN caches: {error}"); + warn!("Failed to invalidate CDN caches: {error:#}"); } let result = ctx.invalidate_cdns(&conn, dist, INDEX_JSON_PATH); if let Err(error) = result.await { - warn!("Failed to invalidate CDN caches: {error}"); + warn!("Failed to invalidate CDN caches: {error:#}"); } info!("CDN caches invalidated"); diff --git a/src/worker/jobs/rss/mod.rs b/src/worker/jobs/rss/mod.rs index e5fd5ddd4bf..03b063cabb3 100644 --- a/src/worker/jobs/rss/mod.rs +++ b/src/worker/jobs/rss/mod.rs @@ -38,7 +38,7 @@ async fn publish_channel( let dist = CloudFrontDistribution::Static; if let Err(error) = ctx.invalidate_cdns(conn, dist, path.as_ref()).await { - warn!("Failed to invalidate CDN caches: {error}"); + warn!("Failed to invalidate CDN caches: {error:#}"); } Ok(()) diff --git a/src/worker/jobs/typosquat.rs b/src/worker/jobs/typosquat.rs index 29b60141b42..605b7f0ce40 100644 --- a/src/worker/jobs/typosquat.rs +++ b/src/worker/jobs/typosquat.rs @@ -90,7 +90,7 @@ async fn check( { error!( ?recipient, - "Failed to send possible typosquat notification: {error}" + "Failed to send possible typosquat notification: {error:#}" ); } }