diff --git a/crates/api/src/main.rs b/crates/api/src/main.rs index 7e23a22d..24ed58c5 100644 --- a/crates/api/src/main.rs +++ b/crates/api/src/main.rs @@ -47,8 +47,8 @@ async fn rproxy( .rproxy_client .request(req) .await - .map_err(|err| { - error!("failed to serve reverse proxy to dotnet-api: {:?}", err); + .map_err(|error| { + error!(?error, "failed to serve reverse proxy to dotnet-api"); StatusCode::BAD_GATEWAY })? .into_response()) diff --git a/crates/api/src/middleware/ratelimit.rs b/crates/api/src/middleware/ratelimit.rs index 3c4a6be4..29cb205b 100644 --- a/crates/api/src/middleware/ratelimit.rs +++ b/crates/api/src/middleware/ratelimit.rs @@ -52,7 +52,7 @@ pub fn ratelimiter(f: F) -> FromFnLayer, T> { .await { Ok(_) => info!("connected to redis for request rate limiting"), - Err(err) => error!("could not load redis script: {}", err), + Err(error) => error!(?error, "could not load redis script"), } } else { error!("could not wait for connection to load redis script!"); @@ -212,8 +212,8 @@ pub async fn do_request_ratelimited( return response; } - Err(err) => { - tracing::error!("error getting ratelimit info: {}", err); + Err(error) => { + tracing::error!(?error, "error getting ratelimit info"); return json_err( StatusCode::INTERNAL_SERVER_ERROR, r#"{"message": "500: internal server error", "code": 0}"#.to_string(), diff --git a/crates/api/src/util.rs b/crates/api/src/util.rs index 0abb1337..35a5bf0d 100644 --- a/crates/api/src/util.rs +++ b/crates/api/src/util.rs @@ -11,7 +11,7 @@ pub fn header_or_unknown(header: Option<&HeaderValue>) -> &str { match value.to_str() { Ok(v) => v, Err(err) => { - error!("failed to parse header value {:#?}: {:#?}", value, err); + error!(?err, ?value, "failed to parse header value"); "failed to parse" } } @@ -34,11 +34,7 @@ where .unwrap(), ), None => { - error!( - "error in handler {}: {:#?}", - std::any::type_name::(), - error - ); + error!(?error, "error in handler {}", std::any::type_name::(),); json_err( StatusCode::INTERNAL_SERVER_ERROR, r#"{"message": "500: Internal Server Error", "code": 0}"#.to_string(), @@ -48,8 +44,8 @@ where } } -pub fn handle_panic(err: Box) -> axum::response::Response { - error!("caught panic from handler: {:#?}", err); +pub fn handle_panic(error: Box) -> axum::response::Response { + error!(?error, "caught panic from handler"); json_err( StatusCode::INTERNAL_SERVER_ERROR, r#"{"message": "500: Internal Server Error", "code": 0}"#.to_string(), diff --git a/crates/avatars/src/cleanup.rs b/crates/avatars/src/cleanup.rs index 83327cf9..9b5ed249 100644 --- a/crates/avatars/src/cleanup.rs +++ b/crates/avatars/src/cleanup.rs @@ -38,8 +38,8 @@ async fn real_main() -> anyhow::Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; match cleanup_job(pool.clone(), bucket.clone()).await { Ok(()) => {} - Err(err) => { - error!("failed to run avatar cleanup job: {}", err); + Err(error) => { + error!(?error, "failed to run avatar cleanup job"); // sentry } } diff --git a/crates/avatars/src/main.rs b/crates/avatars/src/main.rs index b6f7a2c7..b551cc41 100644 --- a/crates/avatars/src/main.rs +++ b/crates/avatars/src/main.rs @@ -232,26 +232,11 @@ async fn real_main() -> anyhow::Result<()> { Ok(()) } -struct AppError(anyhow::Error); - #[derive(Serialize)] struct ErrorResponse { error: String, } -impl IntoResponse for AppError { - fn into_response(self) -> Response { - error!("error handling request: {}", self.0); - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(ErrorResponse { - error: self.0.to_string(), - }), - ) - .into_response() - } -} - impl IntoResponse for PKAvatarError { fn into_response(self) -> Response { let status_code = match self { @@ -278,12 +263,3 @@ impl IntoResponse for PKAvatarError { .into_response() } } - -impl From for AppError -where - E: Into, -{ - fn from(err: E) -> Self { - Self(err.into()) - } -} diff --git a/crates/avatars/src/migrate.rs b/crates/avatars/src/migrate.rs index 87a5747d..8c72267c 100644 --- a/crates/avatars/src/migrate.rs +++ b/crates/avatars/src/migrate.rs @@ -129,9 +129,9 @@ pub async fn worker(worker_id: u32, state: Arc) { Ok(()) => {} Err(e) => { error!( - "error in migrate worker {}: {}", - worker_id, - e.source().unwrap_or(&e) + error = e.source().unwrap_or(&e) + ?worker_id, + "error in migrate worker", ); tokio::time::sleep(Duration::from_secs(5)).await; } diff --git a/crates/avatars/src/process.rs b/crates/avatars/src/process.rs index 61eaaef2..024f40de 100644 --- a/crates/avatars/src/process.rs +++ b/crates/avatars/src/process.rs @@ -84,7 +84,7 @@ pub fn process(data: &[u8], kind: ImageKind) -> Result() { Ok(v) if v.scheme_str() == Some("https") && v.host().is_some() => v, Err(error) => { - error!(?error, "failed to parse uri {}", req.url); + error!(?error, uri = req.url, "failed to parse uri"); return DispatchResponse::BadData.to_string(); } _ => { - error!("uri {} is invalid", req.url); + error!(uri = req.url, "uri is invalid"); return DispatchResponse::BadData.to_string(); } }; diff --git a/crates/gateway/src/discord/gateway.rs b/crates/gateway/src/discord/gateway.rs index 5ca24185..1c0239f5 100644 --- a/crates/gateway/src/discord/gateway.rs +++ b/crates/gateway/src/discord/gateway.rs @@ -124,7 +124,7 @@ pub async fn runner( .increment(1); if let Err(error) = shard_state.socket_closed(shard_id).await { - error!("failed to update shard state for socket closure: {error}"); + error!(?error, "failed to update shard state for socket closure"); } continue; @@ -145,7 +145,7 @@ pub async fn runner( continue; } Err(error) => { - error!("shard {shard_id} failed to parse gateway event: {error}"); + error!(?error, ?shard_id, "failed to parse gateway event"); continue; } }; diff --git a/crates/gateway/src/discord/identify_queue.rs b/crates/gateway/src/discord/identify_queue.rs index 2d523dfa..4df8dc4f 100644 --- a/crates/gateway/src/discord/identify_queue.rs +++ b/crates/gateway/src/discord/identify_queue.rs @@ -78,8 +78,8 @@ async fn request_inner(redis: RedisPool, concurrency: u32, shard_id: u32, tx: on Ok(None) => { // not allowed yet, waiting } - Err(e) => { - error!(shard_id, bucket, "error getting shard allowance: {}", e) + Err(error) => { + error!(?error, ?shard_id, ?bucket, "error getting shard allowance") } } diff --git a/crates/gateway/src/main.rs b/crates/gateway/src/main.rs index 7cab2e76..5cf08f46 100644 --- a/crates/gateway/src/main.rs +++ b/crates/gateway/src/main.rs @@ -129,7 +129,7 @@ async fn real_main() -> anyhow::Result<()> { } } Err(error) => { - error!(error = ?error, "failed to request event target"); + error!(?error, "failed to request event target"); } } } diff --git a/crates/gdpr_worker/src/main.rs b/crates/gdpr_worker/src/main.rs index 7409bdff..e801b9fe 100644 --- a/crates/gdpr_worker/src/main.rs +++ b/crates/gdpr_worker/src/main.rs @@ -42,8 +42,8 @@ async fn real_main() -> anyhow::Result<()> { tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; match run_job(db.clone(), client.clone()).await { Ok(()) => {} - Err(err) => { - error!("failed to run messages gdpr job: {:?}", err); + Err(error) => { + error!(?error, "failed to run messages gdpr job"); } } } @@ -131,8 +131,10 @@ async fn run_job(pool: sqlx::PgPool, discord: Arc) -> any } _ => { error!( - "got unknown error deleting message {}: status={status}, code={code}", - message.mid + ?status, + ?code, + message_id = message.mid, + "got unknown error deleting message", ); } } diff --git a/crates/libpk/src/lib.rs b/crates/libpk/src/lib.rs index 10d174d0..8de69d92 100644 --- a/crates/libpk/src/lib.rs +++ b/crates/libpk/src/lib.rs @@ -81,12 +81,12 @@ macro_rules! main { .build() .unwrap() .block_on(async { - if let Err(err) = libpk::init_metrics() { - tracing::error!("failed to init metrics collector: {err}"); + if let Err(error) = libpk::init_metrics() { + tracing::error!(?error, "failed to init metrics collector"); }; tracing::info!("hello world"); - if let Err(err) = real_main().await { - tracing::error!("failed to run service: {err}"); + if let Err(error) = real_main().await { + tracing::error!(?error, "failed to run service"); }; }); Ok(()) diff --git a/crates/scheduled_tasks/src/main.rs b/crates/scheduled_tasks/src/main.rs index cd0a182b..56d58c7c 100644 --- a/crates/scheduled_tasks/src/main.rs +++ b/crates/scheduled_tasks/src/main.rs @@ -74,8 +74,7 @@ async fn real_main() -> anyhow::Result<()> { info!("running {}", $desc); let before = std::time::Instant::now(); if let Err(error) = $fn(ctx).await { - error!("failed to run {}: {}", $desc, error); - // sentry + error!(?error, "failed to run {}", $desc); } let duration = before.elapsed(); info!("ran {} in {duration:?}", $desc);