From 60fc50644fd6bf3fc8833d434777852ea17c2bea Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 26 Apr 2023 12:52:20 +0200 Subject: [PATCH] cli: Fix `Message::get` bug We were not propagating the error properly. --- radicle-cli/src/commands/comment.rs | 2 +- radicle-cli/src/commands/patch/create.rs | 2 +- radicle-cli/src/commands/patch/update.rs | 2 +- radicle-cli/src/commands/review.rs | 2 +- radicle-cli/src/terminal/patch.rs | 10 +++------- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/radicle-cli/src/commands/comment.rs b/radicle-cli/src/commands/comment.rs index 90294f88..4d5bace0 100644 --- a/radicle-cli/src/commands/comment.rs +++ b/radicle-cli/src/commands/comment.rs @@ -93,7 +93,7 @@ fn comment( repo: &storage::git::Repository, signer: impl Signer, ) -> anyhow::Result<()> { - let message = options.message.clone().get("Enter a comment..."); + let message = options.message.clone().get("Enter a comment...")?; if message.is_empty() { return Ok(()); } diff --git a/radicle-cli/src/commands/patch/create.rs b/radicle-cli/src/commands/patch/create.rs index 0a3f921c..72a7fd14 100644 --- a/radicle-cli/src/commands/patch/create.rs +++ b/radicle-cli/src/commands/patch/create.rs @@ -34,7 +34,7 @@ pub fn handle_patch_message( let commit_message = head_commit .message() .ok_or(anyhow!("commit summary is not valid UTF-8; aborting"))?; - let message = message.get(&format!("{commit_message}{PATCH_MSG}")); + let message = message.get(&format!("{commit_message}{PATCH_MSG}"))?; let message = message.replace(PATCH_MSG.trim(), ""); // Delete help message. let (title, description) = message.split_once("\n\n").unwrap_or((&message, "")); let (title, description) = (title.trim(), description.trim()); diff --git a/radicle-cli/src/commands/patch/update.rs b/radicle-cli/src/commands/patch/update.rs index 4a7c0921..9f155735 100644 --- a/radicle-cli/src/commands/patch/update.rs +++ b/radicle-cli/src/commands/patch/update.rs @@ -100,7 +100,7 @@ pub fn run( let head_oid = branch_oid(&head_branch)?; let base_oid = workdir.merge_base(*target_oid, *head_oid)?; - let message = message.get(REVISION_MSG); + let message = message.get(REVISION_MSG)?; let message = message.replace(REVISION_MSG.trim(), ""); let message = message.trim(); let signer = term::signer(profile)?; diff --git a/radicle-cli/src/commands/review.rs b/radicle-cli/src/commands/review.rs index 0d517d87..da4f1a60 100644 --- a/radicle-cli/src/commands/review.rs +++ b/radicle-cli/src/commands/review.rs @@ -144,7 +144,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { .revisions() .nth(revision_ix) .ok_or_else(|| anyhow!("revision R{} does not exist", revision_ix))?; - let message = options.message.get(REVIEW_HELP_MSG); + let message = options.message.get(REVIEW_HELP_MSG)?; let message = message.replace(REVIEW_HELP_MSG.trim(), ""); let message = if message.is_empty() { None diff --git a/radicle-cli/src/terminal/patch.rs b/radicle-cli/src/terminal/patch.rs index e1c2e464..8bd66c55 100644 --- a/radicle-cli/src/terminal/patch.rs +++ b/radicle-cli/src/terminal/patch.rs @@ -16,20 +16,16 @@ pub enum Message { impl Message { /// Get the `Message` as a string according to the method. - pub fn get(self, help: &str) -> String { + pub fn get(self, help: &str) -> std::io::Result { let comment = match self { - Message::Edit => term::Editor::new() - .extension("markdown") - .edit(help) - .ok() - .flatten(), + Message::Edit => term::Editor::new().extension("markdown").edit(help)?, Message::Blank => None, Message::Text(c) => Some(c), }; let comment = comment.unwrap_or_default(); let comment = comment.trim(); - comment.to_owned() + Ok(comment.to_owned()) } pub fn append(&mut self, arg: &str) {