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 <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
static
struct lttng_condition *parse_condition(const char *condition_name, int *argc,
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;
{
int i;
struct lttng_condition *cond;
- 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);
static
struct lttng_action *parse_action(const char *action_name, int *argc,
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;
{
int i;
struct lttng_action *action;
- 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);
}
condition = parse_condition(arg, &my_argc, &my_argv,
}
condition = parse_condition(arg, &my_argc, &my_argv,
+ argc - my_argc, argc - my_argc - ingested_args,
+ my_argv[-ingested_args]);
if (!condition) {
/*
* An error message was already printed by
if (!condition) {
/*
* An error message was already printed by
case OPT_ACTION:
{
action = parse_action(arg, &my_argc, &my_argv,
case OPT_ACTION:
{
action = parse_action(arg, &my_argc, &my_argv,
+ argc - my_argc, argc - my_argc - ingested_args,
+ my_argv[-ingested_args]);
if (!action) {
/*
* An error message was already printed by
if (!action) {
/*
* An error message was already printed by
#include <common/error.h>
#include <common/string-utils/string-utils.h>
#include <common/error.h>
#include <common/string-utils/string-utils.h>
-#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.
/*
* Given argpar error status `status` and error `error`, return a formatted
* error message describing the error.
#include <common/argpar/argpar.h>
#include <common/string-utils/format.h>
#include <common/argpar/argpar.h>
#include <common/string-utils/format.h>
+#define WHILE_PARSING_ARG_N_ARG_FMT "While parsing argument #%d (`%s`): "
+
enum parse_next_item_status
{
PARSE_NEXT_ITEM_STATUS_OK = 0,
enum parse_next_item_status
{
PARSE_NEXT_ITEM_STATUS_OK = 0,
# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"
# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"
FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
"Error: While parsing argument #2 (\`--condition\`): Missing required argument for option \`--condition\`" \
--condition
test_failure "unknown --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'" \
+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" \
# `--condition event-rule-matches` failures
test_failure "missing args after --condition event-rule-matches" \