summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-03-11 08:24:59 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-03-11 08:27:46 +0100
commit04205d2b5201af21186cc257b4019752b1d1173d (patch)
treefd24de9f9550938648b67b0c3c1dcccdc1c78097 /src/main.rs
parenta282aa78f8ef025cc4d870788a5e7e8ae623f57a (diff)
Add more error context if CLI command fails
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs54
1 files changed, 41 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index bb5dd88..b93df83 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -51,6 +51,7 @@ extern crate diesel;
use std::path::PathBuf;
use anyhow::anyhow;
+use anyhow::Context;
use anyhow::Result;
use clap::ArgMatches;
use logcrate::debug;
@@ -135,65 +136,92 @@ async fn main() -> Result<()> {
repo,
&repo_path,
)
- .await?
+ .await
+ .context("build command failed")?
}
Some(("what-depends", matches)) => {
let repo = load_repo()?;
- crate::commands::what_depends(matches, &config, repo).await?
+ crate::commands::what_depends(matches, &config, repo)
+ .await
+ .context("what-depends command failed")?
}
Some(("dependencies-of", matches)) => {
let repo = load_repo()?;
- crate::commands::dependencies_of(matches, &config, repo).await?
+ crate::commands::dependencies_of(matches, &config, repo)
+ .await
+ .context("dependencies-of command failed")?
}
Some(("versions-of", matches)) => {
let repo = load_repo()?;
- crate::commands::versions_of(matches, repo).await?
+ crate::commands::versions_of(matches, repo)
+ .await
+ .context("versions-of command failed")?
}
Some(("env-of", matches)) => {
let repo = load_repo()?;
- crate::commands::env_of(matches, repo).await?
+ crate::commands::env_of(matches, repo)
+ .await
+ .context("env-of command failed")?
}
Some(("find-artifact", matches)) => {
let repo = load_repo()?;
let conn = crate::db::establish_connection(db_connection_config)?;
- crate::commands::find_artifact(matches, &config, progressbars, repo, conn).await?
+ crate::commands::find_artifact(matches, &config, progressbars, repo, conn)
+ .await
+ .context("find-artifact command failed")?
}
Some(("find-pkg", matches)) => {
let repo = load_repo()?;
- crate::commands::find_pkg(matches, &config, repo).await?
+ crate::commands::find_pkg(matches, &config, repo)
+ .await
+ .context("find-pkg command failed")?
}
Some(("source", matches)) => {
let repo = load_repo()?;
- crate::commands::source(matches, &config, repo, progressbars).await?
+ crate::commands::source(matches, &config, repo, progressbars)
+ .await
+ .context("source command failed")?
}
Some(("release", matches)) => {
- crate::commands::release(db_connection_config, &config, matches).await?
+ crate::commands::release(db_connection_config, &config, matches)
+ .await
+ .context("release command failed")?
}
Some(("lint", matches)) => {
let repo = load_repo()?;
- crate::commands::lint(&repo_path, matches, progressbars, &config, repo).await?
+ crate::commands::lint(&repo_path, matches, progressbars, &config, repo)
+ .await
+ .context("lint command failed")?
}
Some(("tree-of", matches)) => {
let repo = load_repo()?;
- crate::commands::tree_of(matches, repo, progressbars).await?
+ crate::commands::tree_of(matches, repo, progressbars)
+ .await
+ .context("tree-of command failed")?
}
Some(("metrics", _)) => {
let repo = load_repo()?;
let conn = crate::db::establish_connection(db_connection_config)?;
- crate::commands::metrics(&repo_path, &config, repo, conn).await?
+ crate::commands::metrics(&repo_path, &config, repo, conn)
+ .await
+ .context("metrics command failed")?
}
- Some(("endpoint", matches)) => crate::commands::endpoint(matches, &config, progressbars).await?,
+ Some(("endpoint", matches)) => {
+ crate::commands::endpoint(matches, &config, progressbars)
+ .await
+ .context("endpoint command failed")?
+ },
Some((other, _)) => return Err(anyhow!("Unknown subcommand: {}", other)),
None => return Err(anyhow!("No subcommand")),
}