Skip to content

Commit

Permalink
filterx: add error reporting to the main eval loop
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Apr 20, 2024
1 parent 4fe5890 commit 113bc9a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/filterx/filterx-eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,35 @@ _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))
g_assert_not_reached();
}

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);
Expand Down

0 comments on commit 113bc9a

Please sign in to comment.