summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-09 18:00:39 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-09 18:00:39 +0100
commit5e1b941300eb94b61b77b05488fca80ebc6b8bf7 (patch)
tree5c932d96fd8a23d81ec25aa03281e970efcfefab
parent16ba0e733729f39108abdaa7fe7264aac06305ed (diff)
Add more error context in case of CLI parsing errors
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/commands/find_pkg.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/commands/find_pkg.rs b/src/commands/find_pkg.rs
index 8a56303..dfdca9b 100644
--- a/src/commands/find_pkg.rs
+++ b/src/commands/find_pkg.rs
@@ -1,3 +1,5 @@
+use anyhow::anyhow;
+use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use clap::ArgMatches;
@@ -16,6 +18,7 @@ pub async fn find_pkg(matches: &ArgMatches, config: &Configuration, repo: Reposi
.map(|mut builder| {
builder.size_limit(1 * 1024 * 1024); // max size for the regex is 1MB. Should be enough for everyone
builder.build()
+ .with_context(|| anyhow!("Failed to build regex from '{}'", matches.value_of("package_name_regex").unwrap()))
.map_err(Error::from)
})
.unwrap()?; // safe by clap
@@ -24,7 +27,9 @@ pub async fn find_pkg(matches: &ArgMatches, config: &Configuration, repo: Reposi
.value_of("package_version_constraint")
.map(String::from)
.map(PackageVersionConstraint::new)
- .transpose()?;
+ .transpose()
+ .context("Parsing package version constraint")
+ .context("A valid package version constraint looks like this: '=1.0.0'")?;
let iter = repo.packages()
.filter(|p| package_name_regex.captures(p.name()).is_some())