[PATCH v2 13/21] libtracefs: Add error message when compare fields fail

From: Steven Rostedt
Date: Tue Aug 03 2021 - 00:26:25 EST


From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>

If the processing of comparing fields fail due to not existing or because
they are not compatible to compare, report a proper error message.

Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
---
src/tracefs-sqlhist.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/tracefs-sqlhist.c b/src/tracefs-sqlhist.c
index e542eb95c17f..ff0869232a9e 100644
--- a/src/tracefs-sqlhist.c
+++ b/src/tracefs-sqlhist.c
@@ -981,6 +981,38 @@ static void selection_error(struct tep_handle *tep,
test_field_exists(tep, sb, expr);
}

+static void compare_error(struct tep_handle *tep,
+ struct sqlhist_bison *sb, struct expr *expr)
+{
+ struct compare *compare = &expr->compare;
+
+ switch (errno) {
+ case ENODEV:
+ case EBADE:
+ break;
+ default:
+ /* System error */
+ return;
+ }
+
+ /* ENODEV means that an event or field does not exist */
+ if (errno == ENODEV) {
+ if (test_field_exists(tep, sb, compare->lval))
+ return;
+ if (test_field_exists(tep, sb, compare->rval))
+ return;
+ return;
+ }
+
+ /* fields exist, but values are not compatible */
+ sb->line_no = compare->lval->line;
+ sb->line_idx = compare->lval->idx;
+
+ parse_error(sb, compare->lval->field.raw,
+ "'%s' is not compatible to compare with '%s'\n",
+ compare->lval->field.raw, compare->rval->field.raw);
+}
+
static struct tracefs_synth *build_synth(struct tep_handle *tep,
const char *name,
struct sql_table *table)
@@ -1073,8 +1105,10 @@ static struct tracefs_synth *build_synth(struct tep_handle *tep,

ret = build_compare(synth, start_system, end_system,
&expr->compare);
- if (ret < 0)
+ if (ret < 0) {
+ compare_error(tep, table->sb, expr);
goto free;
+ }
}

for (expr = table->where; expr; expr = expr->next) {
--
2.30.2