From c11026c5be5d7447110ea8dcdc533d40b5c5f39c Mon Sep 17 00:00:00 2001 From: Rahix Date: Tue, 9 Dec 2025 16:19:21 +0100 Subject: [PATCH] Better handling of id errors from issue API calls --- techtree-manager/src/issue.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/techtree-manager/src/issue.rs b/techtree-manager/src/issue.rs index 9777c43..97cf9d9 100644 --- a/techtree-manager/src/issue.rs +++ b/techtree-manager/src/issue.rs @@ -28,7 +28,7 @@ pub async fn make_bot_comment( .await?; Ok(BotCommentInfo { - id: res.id.expect("TODO"), + id: res.id.context("Missing id for the bot comment")?, body: initial_message.to_owned(), }) } @@ -55,12 +55,16 @@ pub async fn find_bot_comment( let maybe_bot_comment = comments .iter() .rev() - .find(|comment| comment.user.as_ref().expect("TODO").id == Some(-2)); + .find(|comment| comment.user.as_ref().and_then(|u| u.id) == Some(-2)); - Ok(maybe_bot_comment.map(|c| BotCommentInfo { - body: c.body.clone().unwrap_or("".to_owned()), - id: c.id.expect("TODO"), - })) + Ok(maybe_bot_comment + .map(|c| -> anyhow::Result<_> { + Ok(BotCommentInfo { + body: c.body.clone().unwrap_or("".to_owned()), + id: c.id.context("Missing id for the bot comment")?, + }) + }) + .transpose()?) } /// Find existing bot comment or create a new one. @@ -155,7 +159,8 @@ pub async fn remove_stale_label(ctx: &crate::Context, issue_number: u64) -> anyh .iter() .filter(|l| l.name.as_deref() == Some("Stale")) .next() - .map(|l| l.id.expect("TODO")); + .map(|l| l.id.ok_or(anyhow::anyhow!("`Stale` label has no ID"))) + .transpose()?; if let Some(stale_label_id) = stale_label_id { log::info!("Removing `Stale` label from issue #{issue_number}...");