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:
parent
01bed73a60
commit
1e66c57643
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ impl Args for Options {
|
|||
|
||||
commits.push(rev);
|
||||
}
|
||||
_ => return Err(anyhow::anyhow!(arg.unexpected())),
|
||||
_ => anyhow::bail!(arg.unexpected()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ impl Args for Options {
|
|||
|
||||
name = Some(val);
|
||||
}
|
||||
_ => return Err(anyhow::anyhow!(arg.unexpected())),
|
||||
_ => anyhow::bail!(arg.unexpected()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue