Skip to content

Commit 7764894

Browse files
committed
Use proper user-facing error message with unexpected Zulip inputs
1 parent 56488c9 commit 7764894

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/interactions.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ impl<'a> ErrorComment<'a> {
2424
}
2525
}
2626

27-
pub async fn post(&self, client: &GithubClient) -> anyhow::Result<Comment> {
27+
pub fn markdown(message: &str) -> anyhow::Result<String> {
2828
let mut body = String::new();
29-
writeln!(body, "**Error**: {}", self.message)?;
29+
writeln!(body, "**Error**: {message}")?;
3030
writeln!(body)?;
3131
writeln!(
3232
body,
3333
"Please file an issue on GitHub at [triagebot](https://github.com/rust-lang/triagebot) if there's \
3434
a problem with this bot, or reach out on [#t-infra](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra) on Zulip."
3535
)?;
36+
Ok(body)
37+
}
38+
39+
pub async fn post(&self, client: &GithubClient) -> anyhow::Result<Comment> {
40+
let body = Self::markdown(&self.message)?;
3641
self.issue.post_comment(client, &body).await
3742
}
3843
}

src/zulip.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::handlers::Context;
1212
use crate::handlers::docs_update::docs_update;
1313
use crate::handlers::pr_tracking::get_assigned_prs;
1414
use crate::handlers::project_goals::{self, ping_project_goals_owners};
15+
use crate::interactions::ErrorComment;
1516
use crate::utils::pluralize;
1617
use crate::zulip::api::{MessageApiResponse, Recipient};
1718
use crate::zulip::client::ZulipClient;
@@ -101,7 +102,13 @@ pub async fn webhook(
101102
Ok(req) => req,
102103
Err(rejection) => {
103104
tracing::error!(?rejection);
104-
return rejection.into_response();
105+
return Json(Response {
106+
content: ErrorComment::markdown(
107+
"unable to handle this Zulip request: invalid JSON input",
108+
)
109+
.expect("creating a error message without fail"),
110+
})
111+
.into_response();
105112
}
106113
};
107114

0 commit comments

Comments
 (0)