Просмотр исходного кода

Add some debug logging for request building

It's suspected that there's a failure of some kind arising when we attempt to
set labels on GitHub issues, but it isn't yet clear what that failure is.

Our logs so far just say "builder error: unsupported value" which is pretty
unhelpful, though it does seem like it is coming from reqwest (the "builder
error" string at least).
Mark Rousskov 4 лет назад
Родитель
Сommit
2f0fddb31b
2 измененных файлов с 15 добавлено и 11 удалено
  1. 10 6
      src/github.rs
  2. 5 5
      src/handlers/major_change.rs

+ 10 - 6
src/github.rs

@@ -18,11 +18,13 @@ pub struct User {
 }
 
 impl GithubClient {
-    async fn _send_req(&self, req: RequestBuilder) -> Result<(Response, String), reqwest::Error> {
+    async fn _send_req(&self, req: RequestBuilder) -> anyhow::Result<(Response, String)> {
         const MAX_ATTEMPTS: usize = 2;
         log::debug!("_send_req with {:?}", req);
-        let req = req.build()?;
         let req_dbg = format!("{:?}", req);
+        let req = req
+            .build()
+            .with_context(|| format!("building reqwest {}", req_dbg))?;
 
         let mut resp = self.client.execute(req.try_clone().unwrap()).await?;
         if let Some(sleep) = Self::needs_retry(&resp).await {
@@ -272,7 +274,7 @@ where
 #[derive(Debug)]
 pub enum AssignmentError {
     InvalidAssignee,
-    Http(reqwest::Error),
+    Http(anyhow::Error),
 }
 
 #[derive(Debug)]
@@ -516,9 +518,11 @@ impl Issue {
                 }
             }
             Err(e) => {
-                if e.status() == Some(reqwest::StatusCode::NOT_FOUND) {
-                    log::debug!("set_assignee: assignee is invalid, returning");
-                    return Err(AssignmentError::InvalidAssignee);
+                if let Some(e) = e.downcast_ref::<reqwest::Error>() {
+                    if e.status() == Some(reqwest::StatusCode::NOT_FOUND) {
+                        log::debug!("set_assignee: assignee is invalid, returning");
+                        return Err(AssignmentError::InvalidAssignee);
+                    }
                 }
                 log::debug!("set_assignee: get {} failed, {:?}", check_url, e);
                 return Err(AssignmentError::Http(e));

+ 5 - 5
src/handlers/major_change.rs

@@ -63,12 +63,12 @@ impl Handler for MajorChangeHandler {
                 // All other issue events are ignored
                 return Ok(None);
             }
-            Event::IssueComment(e) => {}
+            Event::IssueComment(_) => {}
         }
 
         let mut input = Input::new(&body, &ctx.username);
         let command = input.parse_command();
-        
+
         if let Some(previous) = event.comment_from() {
             let mut prev_input = Input::new(&previous, &ctx.username);
             let prev_command = prev_input.parse_command();
@@ -76,7 +76,7 @@ impl Handler for MajorChangeHandler {
                 return Ok(None);
             }
         }
-        
+
         match command {
             Command::Second(Ok(SecondCommand)) => Ok(Some(Invocation::Second)),
             _ => Ok(None),
@@ -215,7 +215,7 @@ async fn handle_input(
     let zulip_req = zulip_req.send(&ctx.github.raw());
 
     let (gh_res, zulip_res) = futures::join!(github_req, zulip_req);
-    gh_res?;
-    zulip_res?;
+    zulip_res.context("zulip post failed")?;
+    gh_res.context("label setting failed")?;
     Ok(())
 }