Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Replace return Err(anyhow!()) with anyhow::bail!()
Merged did:key:z6MkwcUR...q1kL opened 8 months ago

This is equivalent to before, but reduces cognitive load when browsing the source.

21 files changed +26 -32 01bed73a 1e66c576
modified crates/radicle-cli/src/commands/auth.rs
@@ -63,7 +63,7 @@ impl Args for Options {
                Long("help") | Short('h') => {
                    return Err(Error::Help.into());
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/block.rs
@@ -61,12 +61,12 @@ impl Args for Options {
                    } else if let Ok(nid) = args::nid(&val) {
                        target = Some(Target::Node(nid));
                    } else {
-
                        return Err(anyhow::anyhow!(
+
                        anyhow::bail!(
                            "invalid repository or node specified, see `rad block --help`"
-
                        ));
+
                        )
                    }
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/checkout.rs
@@ -59,7 +59,7 @@ impl Args for Options {
                Value(val) if id.is_none() => {
                    id = Some(term::args::rid(&val)?);
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/clean.rs
@@ -55,7 +55,7 @@ impl Args for Options {
                Value(val) if id.is_none() => {
                    id = Some(term::args::rid(&val)?);
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/diff.rs
@@ -65,7 +65,7 @@ impl Args for Options {

                    commits.push(rev);
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/fork.rs
@@ -43,7 +43,7 @@ impl Args for Options {
                Value(val) if rid.is_none() => {
                    rid = Some(args::rid(&val)?);
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/help.rs
@@ -49,7 +49,7 @@ impl Args for Options {
        let mut parser = lexopt::Parser::from_args(args);

        if let Some(arg) = parser.next()? {
-
            return Err(anyhow::anyhow!(arg.unexpected()));
+
            anyhow::bail!(arg.unexpected());
        }
        Err(Error::HelpManual { name: "rad" }.into())
    }
modified crates/radicle-cli/src/commands/inbox.rs
@@ -140,7 +140,7 @@ impl Args for Options {
                    let id = term::args::number(&val)? as NotificationId;
                    ids.push(id);
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }
        let mode = if ids.is_empty() {
modified crates/radicle-cli/src/commands/init.rs
@@ -159,7 +159,7 @@ impl Args for Options {
                Value(val) if path.is_none() => {
                    path = Some(val.into());
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/inspect.rs
@@ -120,7 +120,7 @@ impl Args for Options {
                            .context("Supplied argument is not a valid path")?;
                    }
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/ls.rs
@@ -68,7 +68,7 @@ impl Args for Options {
                    public = true;
                }
                Long("verbose") | Short('v') => verbose = true,
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/patch.rs
@@ -727,7 +727,7 @@ impl Args for Options {
                    let val = string(&val);
                    patch_id = Some(Rev::from(val));
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/remote.rs
@@ -152,7 +152,7 @@ impl Args for Options {

                    name = Some(val);
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/self.rs
@@ -79,7 +79,7 @@ impl Args for Options {
                Long("help") | Short('h') => {
                    return Err(Error::Help.into());
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/stats.rs
@@ -80,7 +80,7 @@ impl Args for Options {
                Long("help") | Short('h') => {
                    return Err(Error::Help.into());
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/unblock.rs
@@ -60,12 +60,12 @@ impl Args for Options {
                    } else if let Ok(nid) = args::nid(&val) {
                        target = Some(Target::Node(nid));
                    } else {
-
                        return Err(anyhow::anyhow!(
+
                        anyhow::bail!(
                            "invalid repository or remote specified, see `rad unblock --help`"
-
                        ));
+
                        )
                    }
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/commands/watch.rs
@@ -100,7 +100,7 @@ impl Args for Options {
                Long("help") | Short('h') => {
                    return Err(Error::Help.into());
                }
-
                _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
                _ => anyhow::bail!(arg.unexpected()),
            }
        }

modified crates/radicle-cli/src/main.rs
@@ -79,7 +79,7 @@ fn parse_args() -> anyhow::Result<Command> {
                    command = Some(Command::Other(args))
                }
            }
-
            _ => return Err(anyhow::anyhow!(arg.unexpected())),
+
            _ => anyhow::bail!(arg.unexpected()),
        }
    }
    if let Some(Command::Version { json: j }) = &mut command {
modified crates/radicle-cli/src/terminal/args.rs
@@ -85,10 +85,7 @@ pub fn format(arg: lexopt::Arg) -> OsString {

pub fn finish(unparsed: Vec<OsString>) -> anyhow::Result<()> {
    if let Some(arg) = unparsed.first() {
-
        return Err(anyhow::anyhow!(
-
            "unexpected argument `{}`",
-
            arg.to_string_lossy()
-
        ));
+
        anyhow::bail!("unexpected argument `{}`", arg.to_string_lossy())
    }
    Ok(())
}
modified crates/radicle-cli/src/terminal/io.rs
@@ -52,9 +52,9 @@ pub fn signer(profile: &Profile) -> anyhow::Result<BoxedDevice> {
    let passphrase = match passphrase(validator) {
        Ok(p) => p,
        Err(inquire::InquireError::NotTTY) => {
-
            return Err(anyhow::anyhow!(
+
            anyhow::bail!(
                "running in non-interactive mode, please set `{RAD_PASSPHRASE}` to unseal your key",
-
            ));
+
            )
        }
        Err(e) => return Err(e.into()),
    };
modified crates/radicle-term/src/args.rs
@@ -66,10 +66,7 @@ pub fn format(arg: lexopt::Arg) -> OsString {

pub fn finish(unparsed: Vec<OsString>) -> anyhow::Result<()> {
    if let Some(arg) = unparsed.first() {
-
        return Err(anyhow::anyhow!(
-
            "unexpected argument `{}`",
-
            arg.to_string_lossy()
-
        ));
+
        anyhow::bail!("unexpected argument `{}`", arg.to_string_lossy())
    }
    Ok(())
}