From: Simon Marchi Date: Tue, 24 Aug 2021 21:50:32 +0000 (-0400) Subject: lttng: mention argument number on unknown action / condition name X-Git-Tag: v2.13.2~8 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9d28679a3d23e2404d42fd9f8abe0002797a6213;p=lttng-tools.git lttng: mention argument number on unknown action / condition name When a unrecognized condition or action name is given, the error message does not contain the part that mentions the argument index, like argument parsing error messages have: $ lttng add-trigger --action notify --condition pouet Error: Unknown condition name 'pouet' I think it would be useful to have it, it can help when you have really long command lines (something possible with add-trigger). The result is: $ lttng add-trigger --action notify --condition pouet Error: While parsing argument #4 (`--condition`): Unknown condition name 'pouet' $ lttng add-trigger --action notify --condition=pouet Error: While parsing argument #4 (`--condition=pouet`): Unknown condition name 'pouet' $ lttng add-trigger --condition event-rule-matches --action pouet Error: While parsing argument #4 (`--action`): Unknown action name: pouet $ lttng add-trigger --condition event-rule-matches --action=pouet Error: While parsing argument #4 (`--action=pouet`): Unknown action name: pouet Change-Id: Ic1a00cffa87ea7b3569b24c7417a00d7a52555f2 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/add_trigger.c b/src/bin/lttng/commands/add_trigger.c index 109daba97..d2880b347 100644 --- a/src/bin/lttng/commands/add_trigger.c +++ b/src/bin/lttng/commands/add_trigger.c @@ -1416,7 +1416,8 @@ struct condition_descr condition_descrs[] = { static struct lttng_condition *parse_condition(const char *condition_name, int *argc, - const char ***argv, int argc_offset) + const char ***argv, int argc_offset, int orig_arg_index, + const char *orig_arg) { int i; struct lttng_condition *cond; @@ -1430,7 +1431,8 @@ struct lttng_condition *parse_condition(const char *condition_name, int *argc, } if (!descr) { - ERR("Unknown condition name '%s'", condition_name); + ERR(WHILE_PARSING_ARG_N_ARG_FMT "Unknown condition name '%s'", + orig_arg_index + 1, orig_arg, condition_name); goto error; } @@ -2097,7 +2099,8 @@ struct action_descr action_descrs[] = { static struct lttng_action *parse_action(const char *action_name, int *argc, - const char ***argv, int argc_offset) + const char ***argv, int argc_offset, int orig_arg_index, + const char *orig_arg) { int i; struct lttng_action *action; @@ -2111,7 +2114,8 @@ struct lttng_action *parse_action(const char *action_name, int *argc, } if (!descr) { - ERR("Unknown action name: %s", action_name); + ERR(WHILE_PARSING_ARG_N_ARG_FMT "Unknown action name: %s", + orig_arg_index + 1, orig_arg, action_name); goto error; } @@ -2247,7 +2251,8 @@ int cmd_add_trigger(int argc, const char **argv) } condition = parse_condition(arg, &my_argc, &my_argv, - argc - my_argc); + argc - my_argc, argc - my_argc - ingested_args, + my_argv[-ingested_args]); if (!condition) { /* * An error message was already printed by @@ -2261,7 +2266,8 @@ int cmd_add_trigger(int argc, const char **argv) case OPT_ACTION: { action = parse_action(arg, &my_argc, &my_argv, - argc - my_argc); + argc - my_argc, argc - my_argc - ingested_args, + my_argv[-ingested_args]); if (!action) { /* * An error message was already printed by diff --git a/src/common/argpar-utils/argpar-utils.c b/src/common/argpar-utils/argpar-utils.c index c2fac926f..141a1d481 100644 --- a/src/common/argpar-utils/argpar-utils.c +++ b/src/common/argpar-utils/argpar-utils.c @@ -12,8 +12,6 @@ #include #include -#define WHILE_PARSING_ARG_N_ARG_FMT "While parsing argument #%d (`%s`): " - /* * Given argpar error status `status` and error `error`, return a formatted * error message describing the error. diff --git a/src/common/argpar-utils/argpar-utils.h b/src/common/argpar-utils/argpar-utils.h index 4d7009e59..37128a48c 100644 --- a/src/common/argpar-utils/argpar-utils.h +++ b/src/common/argpar-utils/argpar-utils.h @@ -14,6 +14,8 @@ #include #include +#define WHILE_PARSING_ARG_N_ARG_FMT "While parsing argument #%d (`%s`): " + enum parse_next_item_status { PARSE_NEXT_ITEM_STATUS_OK = 0, diff --git a/tests/regression/tools/trigger/test_add_trigger_cli b/tests/regression/tools/trigger/test_add_trigger_cli index 624302795..03f8b4242 100755 --- a/tests/regression/tools/trigger/test_add_trigger_cli +++ b/tests/regression/tools/trigger/test_add_trigger_cli @@ -23,7 +23,7 @@ TESTDIR="$CURDIR/../../.." # shellcheck source=../../../utils/utils.sh source "$TESTDIR/utils/utils.sh" -plan_tests 286 +plan_tests 289 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" @@ -453,8 +453,11 @@ test_failure "missing args after --condition" \ "Error: While parsing argument #2 (\`--condition\`): Missing required argument for option \`--condition\`" \ --condition test_failure "unknown --condition" \ - "Error: Unknown condition name 'zoofest'" \ + "Error: While parsing argument #2 (\`--condition\`): Unknown condition name 'zoofest'" \ --condition zoofest +test_failure "unknown --condition=" \ + "Error: While parsing argument #2 (\`--condition=zoofest\`): Unknown condition name 'zoofest'" \ + --condition=zoofest # `--condition event-rule-matches` failures test_failure "missing args after --condition event-rule-matches" \