From 113bc9a56d5a86177485376c89a1bdcb6ce251b0 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Thu, 18 Apr 2024 15:22:05 +0200 Subject: [PATCH] filterx: add error reporting to the main eval loop Signed-off-by: Balazs Scheidler --- lib/filterx/filterx-eval.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/filterx/filterx-eval.c b/lib/filterx/filterx-eval.c index 9282d4d9d5..3f0f2f36b6 100644 --- a/lib/filterx/filterx-eval.c +++ b/lib/filterx/filterx-eval.c @@ -111,14 +111,21 @@ _evaluate_statement(FilterXExpr *expr) FilterXObject *res = filterx_expr_eval(expr); gboolean success = FALSE; - if (res) - success = filterx_object_truthy(res); + if (!res) + { + msg_debug("FILTERX ERROR", + filterx_expr_format_location_tag(expr), + evt_tag_str("error", filterx_eval_get_last_error())); + return FALSE; + } + filterx_eval_clear_errors(); + success = filterx_object_truthy(res); if (!success || trace_flag) { GString *buf = scratch_buffers_alloc(); - if (res && !filterx_object_repr(res, buf)) + if (!filterx_object_repr(res, buf)) { LogMessageValueType t; if (!filterx_object_marshal(res, buf, &t)) @@ -126,20 +133,13 @@ _evaluate_statement(FilterXExpr *expr) } if (!success) - msg_debug("Filterx expression failed", - evt_tag_printf("expr", "%s:%d:%d| %s", - expr->lloc.name, expr->lloc.first_line, expr->lloc.first_column, - expr->expr_text ? : "n/a"), - evt_tag_str("status", res == NULL ? "error" : "falsy"), + msg_debug("FILTERX FALSY", + filterx_expr_format_location_tag(expr), evt_tag_mem("value", buf->str, buf->len)); else - msg_trace("FILTERX", - evt_tag_printf("expr", "%s:%d:%d| %s", - expr->lloc.name, expr->lloc.first_line, expr->lloc.first_column, - expr->expr_text ? : "n/a"), - evt_tag_str("status", res == NULL ? "error" : (success ? "truthy" : "falsy")), - evt_tag_mem("value", buf->str, buf->len), - evt_tag_printf("result", "%p", res)); + msg_trace("FILTERX TRUTHY", + filterx_expr_format_location_tag(expr), + evt_tag_mem("value", buf->str, buf->len)); } filterx_object_unref(res);