From 04205d2b5201af21186cc257b4019752b1d1173d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 11 Mar 2021 08:24:59 +0100 Subject: Add more error context if CLI command fails Signed-off-by: Matthias Beyer --- src/main.rs | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'src/main.rs') 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")), } -- cgit v1.2.3