diff --git a/radicle-cli/src/commands/issue.rs b/radicle-cli/src/commands/issue.rs index c4684a0a..d15b8479 100644 --- a/radicle-cli/src/commands/issue.rs +++ b/radicle-cli/src/commands/issue.rs @@ -591,10 +591,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { let id = id.resolve(&repo.backend)?; if let Ok(mut issue) = issues.get_mut(&id) { let signer = term::signer(&profile)?; - let comment_id = comment_id.unwrap_or_else(|| { - let (comment_id, _) = term::io::comment_select(&issue).unwrap(); - *comment_id - }); + let comment_id = match comment_id { + Some(cid) => cid, + None => *term::io::comment_select(&issue).map(|(cid, _)| cid)?, + }; issue.react(comment_id, reaction, true, &signer)?; } } diff --git a/radicle-cli/src/terminal/io.rs b/radicle-cli/src/terminal/io.rs index 9dce1497..334e62f3 100644 --- a/radicle-cli/src/terminal/io.rs +++ b/radicle-cli/src/terminal/io.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use radicle::cob::issue::Issue; use radicle::cob::thread::{Comment, CommentId}; use radicle::crypto::ssh::keystore::MemorySigner; @@ -63,7 +64,7 @@ pub fn signer(profile: &Profile) -> anyhow::Result> { Ok(signer.boxed()) } -pub fn comment_select(issue: &Issue) -> Option<(&CommentId, &Comment)> { +pub fn comment_select(issue: &Issue) -> anyhow::Result<(&CommentId, &Comment)> { let comments = issue.comments().collect::>(); let selection = Select::new( "Which comment do you want to react to?", @@ -71,8 +72,10 @@ pub fn comment_select(issue: &Issue) -> Option<(&CommentId, &Comment)> { ) .with_render_config(*CONFIG) .with_formatter(&|i| comments[i.index].1.body().to_owned()) - .prompt() - .ok()?; + .prompt()?; - comments.get(selection).copied() + comments + .get(selection) + .copied() + .ok_or(anyhow!("failed to perform comment selection")) }