refactor: Replace return Err(anyhow!()) with anyhow::bail!()

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

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2025-08-17 14:49:52 +02:00 committed by Lorenz Leutgeb
parent 01bed73a60
commit 1e66c57643
21 changed files with 26 additions and 32 deletions

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -65,7 +65,7 @@ impl Args for Options {
commits.push(rev);
}
_ => return Err(anyhow::anyhow!(arg.unexpected())),
_ => anyhow::bail!(arg.unexpected()),
}
}

View File

@ -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()),
}
}

View File

@ -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())
}

View File

@ -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() {

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -152,7 +152,7 @@ impl Args for Options {
name = Some(val);
}
_ => return Err(anyhow::anyhow!(arg.unexpected())),
_ => anyhow::bail!(arg.unexpected()),
}
}

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -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()),
}
}

View File

@ -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 {

View File

@ -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(())
}

View File

@ -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()),
};

View File

@ -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(())
}