From d38846baaeeb0bcfb9b19d3a6819a0aa87367042 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 15 Mar 2024 12:41:32 +0100 Subject: [PATCH] cli: Display better errors in `patch ready` Instead of doing nothing and going to sync no change, we should display some error to the users that we haven't been able to apply the changes. --- radicle-cli/src/commands/patch.rs | 9 ++++++++- radicle-cli/src/commands/patch/ready.rs | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/radicle-cli/src/commands/patch.rs b/radicle-cli/src/commands/patch.rs index 27a02ca1..541d9b73 100644 --- a/radicle-cli/src/commands/patch.rs +++ b/radicle-cli/src/commands/patch.rs @@ -743,7 +743,14 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { } Operation::Ready { ref patch_id, undo } => { let patch_id = patch_id.resolve::(&repository.backend)?; - ready::run(&patch_id, undo, &profile, &repository)?; + + if !ready::run(&patch_id, undo, &profile, &repository)? { + if undo { + anyhow::bail!("the patch must be open to be put in draft state"); + } else { + anyhow::bail!("this patch must be in draft state to be put in open state"); + } + } } Operation::Delete { patch_id } => { let patch_id = patch_id.resolve::(&repository.backend)?; diff --git a/radicle-cli/src/commands/patch/ready.rs b/radicle-cli/src/commands/patch/ready.rs index 4ab878ba..6a7147f6 100644 --- a/radicle-cli/src/commands/patch/ready.rs +++ b/radicle-cli/src/commands/patch/ready.rs @@ -8,7 +8,7 @@ pub fn run( undo: bool, profile: &Profile, repository: &Repository, -) -> anyhow::Result<()> { +) -> anyhow::Result { let signer = term::signer(profile)?; let mut patches = profile.patches_mut(repository)?; let Ok(mut patch) = patches.get_mut(patch_id) else { @@ -16,9 +16,9 @@ pub fn run( }; if undo { - patch.unready(&signer)?; + patch.unready(&signer) } else { - patch.ready(&signer)?; + patch.ready(&signer) } - Ok(()) + .map_err(anyhow::Error::from) }