Skip to content

Commit 4aca82a

Browse files
committed
Report client side errors to the user in our GHA logs viewer
1 parent dc5a2db commit 4aca82a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
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 [#t-infra](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra) 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

0 commit comments

Comments
 (0)