Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<reqwest::Error>()
&& 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()
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/gha_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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.
Expand Down Expand Up @@ -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")?;
Expand Down
Loading