Replace dirty unwrap() with expect("TODO")

This makes it obvious where better error handling is still needed.
This commit is contained in:
Rahix 2025-12-09 15:29:21 +01:00
parent 983ceb2076
commit b66e8c8d9c
5 changed files with 25 additions and 15 deletions

View file

@ -123,9 +123,9 @@ fn element_from_issue(issue: &forgejo_api::structs::Issue) -> anyhow::Result<cra
let ty = ty_labels let ty = ty_labels
.first() .first()
.unwrap() .expect("TODO")
.strip_prefix("Type/") .strip_prefix("Type/")
.unwrap() .expect("TODO")
.to_owned(); .to_owned();
let has_completed_label = labels let has_completed_label = labels

View file

@ -28,7 +28,7 @@ pub async fn make_bot_comment(
.await?; .await?;
Ok(BotCommentInfo { Ok(BotCommentInfo {
id: res.id.unwrap(), id: res.id.expect("TODO"),
body: initial_message.to_owned(), body: initial_message.to_owned(),
}) })
} }
@ -55,11 +55,11 @@ pub async fn find_bot_comment(
let maybe_bot_comment = comments let maybe_bot_comment = comments
.iter() .iter()
.rev() .rev()
.find(|comment| comment.user.as_ref().unwrap().id == Some(-2)); .find(|comment| comment.user.as_ref().expect("TODO").id == Some(-2));
Ok(maybe_bot_comment.map(|c| BotCommentInfo { Ok(maybe_bot_comment.map(|c| BotCommentInfo {
body: c.body.clone().unwrap_or("".to_owned()), body: c.body.clone().unwrap_or("".to_owned()),
id: c.id.unwrap(), id: c.id.expect("TODO"),
})) }))
} }
@ -155,7 +155,7 @@ pub async fn remove_stale_label(ctx: &crate::Context, issue_number: u64) -> anyh
.iter() .iter()
.filter(|l| l.name.as_deref() == Some("Stale")) .filter(|l| l.name.as_deref() == Some("Stale"))
.next() .next()
.map(|l| l.id.unwrap()); .map(|l| l.id.expect("TODO"));
if let Some(stale_label_id) = stale_label_id { if let Some(stale_label_id) = stale_label_id {
log::info!("Removing `Stale` label from issue #{issue_number}..."); log::info!("Removing `Stale` label from issue #{issue_number}...");

View file

@ -60,12 +60,12 @@ async fn run() -> anyhow::Result<()> {
"{}/{}", "{}/{}",
meta.issue.repository.owner, meta.issue.repository.name meta.issue.repository.owner, meta.issue.repository.name
)) ))
.unwrap(); .expect("TODO");
let repo_auth_url = token.as_ref().map(|token| { let repo_auth_url = token.as_ref().map(|token| {
let mut repo_auth_url = repo_url.clone(); let mut repo_auth_url = repo_url.clone();
repo_auth_url.set_username("forgejo-actions").unwrap(); repo_auth_url.set_username("forgejo-actions").expect("TODO");
repo_auth_url.set_password(Some(&token)).unwrap(); repo_auth_url.set_password(Some(&token)).expect("TODO");
repo_auth_url repo_auth_url
}); });
@ -138,7 +138,7 @@ async fn run() -> anyhow::Result<()> {
} }
'issues: for issue in tree.iter_issues() { 'issues: for issue in tree.iter_issues() {
let subtree = tree.subtree_for_issue(issue).unwrap(); let subtree = tree.subtree_for_issue(issue).expect("TODO");
let hash = subtree.stable_hash(); let hash = subtree.stable_hash();
let (bot_comment, _is_new) = issue::find_or_make_bot_comment(&ctx, issue) let (bot_comment, _is_new) = issue::find_or_make_bot_comment(&ctx, issue)

View file

@ -84,8 +84,18 @@ pub async fn publish(ctx: &crate::Context, rendered: &RenderedTree) -> anyhow::R
.arg("-C") .arg("-C")
.arg(&rendered.repo_dir) .arg(&rendered.repo_dir)
.arg("add") .arg("add")
.arg(rendered.dot_file.strip_prefix(&rendered.repo_dir).unwrap()) .arg(
.arg(rendered.svg_file.strip_prefix(&rendered.repo_dir).unwrap()) rendered
.dot_file
.strip_prefix(&rendered.repo_dir)
.expect("TODO"),
)
.arg(
rendered
.svg_file
.strip_prefix(&rendered.repo_dir)
.expect("TODO"),
)
.success() .success()
.context("Failed to add generated graph files to git index")?; .context("Failed to add generated graph files to git index")?;

View file

@ -165,8 +165,8 @@ impl Tree {
} }
pub fn add_dependency_by_issue_number(&mut self, dependant: u64, dependency: u64) { pub fn add_dependency_by_issue_number(&mut self, dependant: u64, dependency: u64) {
let a = self.find_element_by_issue_number(dependant).unwrap(); let a = self.find_element_by_issue_number(dependant).expect("TODO");
let b = self.find_element_by_issue_number(dependency).unwrap(); let b = self.find_element_by_issue_number(dependency).expect("TODO");
self.graph.add_edge(a, b, ()); self.graph.add_edge(a, b, ());
} }
@ -422,7 +422,7 @@ impl<'a> Subtree<'a> {
.collect(); .collect();
edges.sort(); edges.sort();
let json_data = serde_json::ser::to_string(&(nodes, edges, HASH_EPOCH)).unwrap(); let json_data = serde_json::ser::to_string(&(nodes, edges, HASH_EPOCH)).expect("TODO");
sha256::digest(json_data) sha256::digest(json_data)
} }
} }