From 75022c347da6f01faa368280b2a4bec07e8bc931 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 1 Nov 2025 11:42:41 +0100 Subject: [PATCH 1/2] Return the inner network error instead of 500 --- src/errors.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index d6192e45..9bad3278 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -61,12 +61,27 @@ pub struct AppError(anyhow::Error); impl IntoResponse for AppError { fn into_response(self) -> Response { - tracing::error!("{:?}", &self.0); - ( - StatusCode::INTERNAL_SERVER_ERROR, - format!("Something went wrong: {}\n\n{REPORT_TO}", self.0), - ) - .into_response() + tracing::error!("app error: {:?}", &self.0); + + // Let's avoid returning 500 when it's a network error and instead return the status + // code of the network request (useful for GHA logs which can get 404, 410 from GitHub). + if let Some(err) = self.0.downcast_ref::() + && let Some(status) = err.status() + { + ( + status, + format!( + "Something went wrong: {}\n\nNetwork error: {err}\n\n{REPORT_TO}", + self.0 + ), + ) + } else { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Something went wrong: {}\n\n{REPORT_TO}", self.0), + ) + } + .into_response() } } From ebd489adfad3c052af18f0faf4c4815fa14978f0 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 1 Nov 2025 11:43:06 +0100 Subject: [PATCH 2/2] gha_log: improve a bit the error messages --- src/gha_logs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gha_logs.rs b/src/gha_logs.rs index 89424c22..72601e0a 100644 --- a/src/gha_logs.rs +++ b/src/gha_logs.rs @@ -88,11 +88,11 @@ pub async fn gha_logs( logs, } = &*'logs: { if let Some(logs) = ctx.gha_logs.write().await.get(&log_uuid) { - tracing::info!("gha_logs: cache hit for {log_uuid}"); + tracing::info!("gha_logs: cache hit for log {log_uuid}"); break 'logs logs; } - tracing::info!("gha_logs: cache miss for {log_uuid}"); + tracing::info!("gha_logs: cache miss for log {log_uuid}"); let repo = github::IssueRepository { organization: owner.to_string(), @@ -104,7 +104,7 @@ pub async fn gha_logs( .github .workflow_run_job(&repo, log_id) .await - .context("unable to fetch job details")?; + .with_context(|| format!("unable to fetch the job details for log {log_id}"))?; // To minimize false positives in paths linked to the GitHub repositories, we // restrict matching to only the second-level directories of the repository. @@ -164,7 +164,7 @@ pub async fn gha_logs( .github .raw_job_logs(&repo, log_id) .await - .context("unable to get the raw logs")?; + .with_context(|| format!("unable to get the raw logs for log {log_id}"))?; let json_logs = serde_json::to_string(&*logs).context("unable to JSON-ify the raw logs")?;