From b6b687f9bb3852ba0a51a26f44f1c2f4a9af1c98 Mon Sep 17 00:00:00 2001 From: shray sharma Date: Mon, 23 Dec 2024 14:45:45 +0100 Subject: [PATCH] upd --- src/conditions/vrl.rs | 46 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/conditions/vrl.rs b/src/conditions/vrl.rs index db8ea2aacdc0f..215bf8a6bec55 100644 --- a/src/conditions/vrl.rs +++ b/src/conditions/vrl.rs @@ -89,6 +89,27 @@ pub struct Vrl { } impl Vrl { + fn format_vrl_error(&self, err: Terminate) -> String { + let formatted_err = match err { + Terminate::Abort(ref err) | Terminate::Error(ref err) => Formatter::new( + &self.source, + vrl::diagnostic::Diagnostic::from( + Box::new((*err).clone()) as Box + ), + ) + .colored() + .to_string(), + }; + format!( + "source execution {}: {}", + if matches!(err, Terminate::Abort(_)) { + "aborted" + } else { + "failed" + }, + formatted_err + ) + } fn run(&self, event: Event) -> (Event, RuntimeResult) { let log_namespace = event .maybe_as_log() @@ -128,30 +149,7 @@ impl Conditional for Vrl { fn check_with_context(&self, event: Event) -> (Result<(), String>, Event) { let (event, result) = self.run(event); - let value_result = result.map_err(|err| match err { - Terminate::Abort(err) => { - let err = Formatter::new( - &self.source, - vrl::diagnostic::Diagnostic::from( - Box::new(err) as Box - ), - ) - .colored() - .to_string(); - format!("source execution aborted: {}", err) - } - Terminate::Error(err) => { - let err = Formatter::new( - &self.source, - vrl::diagnostic::Diagnostic::from( - Box::new(err) as Box - ), - ) - .colored() - .to_string(); - format!("source execution failed: {}", err) - } - }); + let value_result = result.map_err(|err| self.format_vrl_error(err)); let value = match value_result { Ok(value) => value,