From 4fbbf34e70ca4150ef52ee74f1c30a5bd79571bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Guilherme=20Vanz?= Date: Wed, 19 Jun 2024 15:31:17 -0300 Subject: [PATCH] fix: improve error handling in settings validation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the policy settings validation failed, the error message printed twice in the console. This commit fix that by removing a where the error is printed once. It's not possible to improve more the error message because the JSON shown in some error came from a string with the error message returned by the settings validator. It's not possible to kwctl to easily improve that without string manipulations. Signed-off-by: José Guilherme Vanz --- src/main.rs | 10 +++++++++- src/run.rs | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 74901072..301aae62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,7 +247,15 @@ async fn main() -> Result<()> { Some("run") => { if let Some(matches) = matches.subcommand_matches("run") { let pull_and_run_settings = parse_pull_and_run_settings(matches).await?; - run::pull_and_run(&pull_and_run_settings).await?; + run::pull_and_run(&pull_and_run_settings) + .await + .map_err(|e| { + anyhow!( + "Error running policy {}: {}", + pull_and_run_settings.uri, + e.to_string() + ) + })?; } Ok(()) } diff --git a/src/run.rs b/src/run.rs index 49deed94..0f32d392 100644 --- a/src/run.rs +++ b/src/run.rs @@ -168,10 +168,9 @@ pub(crate) async fn pull_and_run(cfg: &PullAndRunSettings) -> Result<()> { // validate the settings given by the user let settings_validation_response = policy_evaluator.validate_settings(&run_env.policy_settings); if !settings_validation_response.valid { - println!("{}", serde_json::to_string(&settings_validation_response)?); return Err(anyhow!( "Provided settings are not valid: {:?}", - settings_validation_response.message + settings_validation_response.message.unwrap_or_default() )); }