Skip to content

Commit 142d2f2

Browse files
authored
Merge pull request #2145 from Urgau/gha-logs-report-client-side-errors
Report client side errors to the user in our GHA logs viewer
2 parents dc5a2db + 5beca3c commit 142d2f2

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/gha_logs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::github::{self, WorkflowRunJob};
22
use crate::handlers::Context;
3+
use crate::interactions::REPORT_TO;
34
use crate::utils::AppError;
45
use anyhow::Context as _;
56
use axum::extract::{Path, State};
@@ -272,6 +273,8 @@ body {{
272273
</style>
273274
<script type="module" nonce="{nonce}">
274275
import {{ AnsiUp }} from '{ANSI_UP_URL}'
276+
277+
try {{
275278
276279
const logs = {logs};
277280
const tree_roots = {tree_roots};
@@ -348,6 +351,11 @@ body {{
348351
inline: hasSmallViewport ? 'start' : 'center'
349352
}});
350353
}}
354+
355+
}} catch (e) {{
356+
console.error(e);
357+
document.body.innerText = `Something went wrong: ${{e}}\n\n{REPORT_TO}`;
358+
}}
351359
</script>
352360
</head>
353361
<body>

src/interactions.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use crate::{
88
};
99
use std::fmt::Write;
1010

11+
pub const REPORT_TO: &str = "Please file an issue on GitHub at [triagebot](https://github.com/rust-lang/triagebot) if there's \
12+
a problem with this bot, or reach out on [#triagebot](https://rust-lang.zulipchat.com/#narrow/channel/224082-triagebot) on Zulip.";
13+
1114
pub struct ErrorComment<'a> {
1215
issue: &'a Issue,
1316
message: String,
@@ -28,11 +31,7 @@ impl<'a> ErrorComment<'a> {
2831
let mut body = String::new();
2932
writeln!(body, "**Error**: {message}")?;
3033
writeln!(body)?;
31-
writeln!(
32-
body,
33-
"Please file an issue on GitHub at [triagebot](https://github.com/rust-lang/triagebot) if there's \
34-
a problem with this bot, or reach out on [#t-infra](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra) on Zulip."
35-
)?;
34+
writeln!(body, "{REPORT_TO}")?;
3635
Ok(body)
3736
}
3837

src/utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::interactions::REPORT_TO;
2+
13
use axum::{
24
http::StatusCode,
35
response::{IntoResponse, Response},
@@ -20,7 +22,7 @@ impl IntoResponse for AppError {
2022
tracing::error!("{:?}", &self.0);
2123
(
2224
StatusCode::INTERNAL_SERVER_ERROR,
23-
format!("Something went wrong: {}", self.0),
25+
format!("Something went wrong: {}\n\n{REPORT_TO}", self.0),
2426
)
2527
.into_response()
2628
}

0 commit comments

Comments
 (0)