From 6d6fffcb4a35e51644df0d62363ec6a5dd3383b3 Mon Sep 17 00:00:00 2001 From: Rahix Date: Tue, 9 Dec 2025 15:33:57 +0100 Subject: [PATCH] Reduce error potentials in type label parsing --- techtree-manager/src/collect.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/techtree-manager/src/collect.rs b/techtree-manager/src/collect.rs index 7d1dcb8..ef3eca1 100644 --- a/techtree-manager/src/collect.rs +++ b/techtree-manager/src/collect.rs @@ -111,22 +111,18 @@ fn element_from_issue(issue: &forgejo_api::structs::Issue) -> anyhow::Result = labels .iter() .filter_map(|l| l.name.as_deref()) - .filter(|l| l.starts_with("Type/")) + .filter_map(|l| l.strip_prefix("Type/")) .collect(); - if ty_labels.len() == 0 { - anyhow::bail!("Issue #{issue_number} has no type label!"); - } - if ty_labels.len() > 1 { - anyhow::bail!("Issue #{issue_number} has more than one type label!"); - } - - let ty = ty_labels - .first() - .expect("TODO") - .strip_prefix("Type/") - .expect("TODO") - .to_owned(); + let ty = match &ty_labels[..] { + [ty] => ty.to_string(), + [] => { + anyhow::bail!("Issue #{issue_number} has no type label!"); + } + [..] => { + anyhow::bail!("Issue #{issue_number} has more than one type label!"); + } + }; let has_completed_label = labels .iter()