DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>, <david.marchand@redhat.com>
Cc: <dev@dpdk.org>
Subject: [PATCH v4 1/6] argparse: refine error message
Date: Mon, 18 Mar 2024 11:18:33 +0000	[thread overview]
Message-ID: <20240318111838.16991-2-fengchengwen@huawei.com> (raw)
In-Reply-To: <20240318111838.16991-1-fengchengwen@huawei.com>

This patch refines the error message.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/argparse/rte_argparse.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/lib/argparse/rte_argparse.c b/lib/argparse/rte_argparse.c
index 2d953f1694..48738cd07b 100644
--- a/lib/argparse/rte_argparse.c
+++ b/lib/argparse/rte_argparse.c
@@ -67,7 +67,7 @@ verify_arg_name(const struct rte_argparse_arg *arg)
 			return -EINVAL;
 		}
 		if (arg->name_long[1] != '-') {
-			ARGPARSE_LOG(ERR, "optional long name %s must only start with '--'",
+			ARGPARSE_LOG(ERR, "optional long name %s doesn't start with '--'",
 				     arg->name_long);
 			return -EINVAL;
 		}
@@ -101,7 +101,7 @@ static int
 verify_arg_help(const struct rte_argparse_arg *arg)
 {
 	if (arg->help == NULL) {
-		ARGPARSE_LOG(ERR, "argument %s must have help info!", arg->name_long);
+		ARGPARSE_LOG(ERR, "argument %s doesn't have help info!", arg->name_long);
 		return -EINVAL;
 	}
 
@@ -116,13 +116,13 @@ verify_arg_has_val(const struct rte_argparse_arg *arg)
 	if (is_arg_positional(arg)) {
 		if (has_val == RTE_ARGPARSE_ARG_REQUIRED_VALUE)
 			return 0;
-		ARGPARSE_LOG(ERR, "argument %s is positional, should has zero or required-val!",
+		ARGPARSE_LOG(ERR, "argument %s is positional, must config required-val!",
 			     arg->name_long);
 		return -EINVAL;
 	}
 
 	if (has_val == 0) {
-		ARGPARSE_LOG(ERR, "argument %s is optional, has-val config wrong!",
+		ARGPARSE_LOG(ERR, "argument %s is optional, has-value config wrong!",
 			     arg->name_long);
 		return -EINVAL;
 	}
@@ -140,13 +140,13 @@ verify_arg_saver(const struct rte_argparse *obj, uint32_t index)
 
 	if (arg->val_saver == NULL) {
 		if (val_type != 0) {
-			ARGPARSE_LOG(ERR, "argument %s parse by callback, val-type must be zero!",
+			ARGPARSE_LOG(ERR, "argument %s parsed by callback, value-type should not be set!",
 				     arg->name_long);
 			return -EINVAL;
 		}
 
 		if (obj->callback == NULL) {
-			ARGPARSE_LOG(ERR, "argument %s parse by callback, but callback is NULL!",
+			ARGPARSE_LOG(ERR, "argument %s parsed by callback, but callback is NULL!",
 				     arg->name_long);
 			return -EINVAL;
 		}
@@ -155,12 +155,12 @@ verify_arg_saver(const struct rte_argparse *obj, uint32_t index)
 	}
 
 	if (val_type == 0 || val_type >= cmp_max) {
-		ARGPARSE_LOG(ERR, "argument %s val-type config wrong!", arg->name_long);
+		ARGPARSE_LOG(ERR, "argument %s value-type config wrong!", arg->name_long);
 		return -EINVAL;
 	}
 
 	if (has_val == RTE_ARGPARSE_ARG_REQUIRED_VALUE && arg->val_set != NULL) {
-		ARGPARSE_LOG(ERR, "argument %s has required value, val-set should be NULL!",
+		ARGPARSE_LOG(ERR, "argument %s has required value, value-set should be NULL!",
 			     arg->name_long);
 		return -EINVAL;
 	}
@@ -175,7 +175,8 @@ verify_arg_flags(const struct rte_argparse *obj, uint32_t index)
 	uint32_t unused_bits = arg_attr_unused_bits(arg);
 
 	if (unused_bits != 0) {
-		ARGPARSE_LOG(ERR, "argument %s flags set wrong!", arg->name_long);
+		ARGPARSE_LOG(ERR, "argument %s flags unused bits should not be set!",
+			     arg->name_long);
 		return -EINVAL;
 	}
 
@@ -189,7 +190,7 @@ verify_arg_flags(const struct rte_argparse *obj, uint32_t index)
 	}
 
 	if (arg->val_saver != NULL) {
-		ARGPARSE_LOG(ERR, "argument %s could occur multiple times, should use callback to parse!",
+		ARGPARSE_LOG(ERR, "argument %s supports multiple times, should use callback to parse!",
 			     arg->name_long);
 		return -EINVAL;
 	}
@@ -536,8 +537,10 @@ parse_arg_autosave(struct rte_argparse_arg *arg, const char *value)
 	return ret;
 }
 
+/* arg_parse indicates the name entered by the user, which can be long-name or short-name. */
 static int
-parse_arg_val(struct rte_argparse *obj, struct rte_argparse_arg *arg, char *value)
+parse_arg_val(struct rte_argparse *obj, const char *arg_name,
+	      struct rte_argparse_arg *arg, char *value)
 {
 	int ret;
 
@@ -546,7 +549,7 @@ parse_arg_val(struct rte_argparse *obj, struct rte_argparse_arg *arg, char *valu
 	else
 		ret = parse_arg_autosave(arg, value);
 	if (ret != 0) {
-		ARGPARSE_LOG(ERR, "argument %s parse value fail!", arg->name_long);
+		ARGPARSE_LOG(ERR, "argument %s parse value fail!", arg_name);
 		return ret;
 	}
 
@@ -582,7 +585,7 @@ parse_args(struct rte_argparse *obj, int argc, char **argv, bool *show_help)
 				return -EINVAL;
 			}
 			arg = find_position_arg(obj, position_index);
-			ret = parse_arg_val(obj, arg, curr_argv);
+			ret = parse_arg_val(obj, arg->name_long, arg, curr_argv);
 			if (ret != 0)
 				return ret;
 			continue;
@@ -629,7 +632,7 @@ parse_args(struct rte_argparse *obj, int argc, char **argv, bool *show_help)
 			/* Do nothing, because it's optional value, only support arg=val or arg. */
 		}
 
-		ret = parse_arg_val(obj, arg, value);
+		ret = parse_arg_val(obj, arg_name, arg, value);
 		if (ret != 0)
 			return ret;
 
-- 
2.17.1


  reply	other threads:[~2024-03-18 11:21 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 13:14 [PATCH 0/4] refine argparse library Chengwen Feng
2024-02-20 13:14 ` [PATCH 1/4] argparse: refine error message Chengwen Feng
2024-02-20 13:15 ` [PATCH 2/4] argparse: remove dead code Chengwen Feng
2024-02-20 13:15 ` [PATCH 3/4] argparse: fix argument flags operate as uint32 type Chengwen Feng
2024-03-06 17:34   ` David Marchand
2024-03-07 13:14     ` fengchengwen
2024-02-20 13:15 ` [PATCH 4/4] test/argparse: refine testcases Chengwen Feng
2024-03-07 13:07 ` [PATCH v2 0/5] refine argparse library Chengwen Feng
2024-03-07 13:07   ` [PATCH v2 1/5] argparse: refine error message Chengwen Feng
2024-03-07 13:07   ` [PATCH v2 2/5] argparse: remove dead code Chengwen Feng
2024-03-07 13:07   ` [PATCH v2 3/5] argparse: replace flag enum with marco Chengwen Feng
2024-03-07 17:43     ` Tyler Retzlaff
2024-03-07 17:58       ` David Marchand
2024-03-07 18:37         ` Tyler Retzlaff
2024-03-07 13:07   ` [PATCH v2 4/5] argparse: fix argument flags operate as uint32 type Chengwen Feng
2024-03-18  2:31     ` Thomas Monjalon
2024-03-18  9:22       ` fengchengwen
2024-03-07 13:07   ` [PATCH v2 5/5] test/argparse: refine testcases Chengwen Feng
2024-03-18  9:18 ` [PATCH v3 0/6] refine argparse library Chengwen Feng
2024-03-18  9:18   ` [PATCH v3 1/6] argparse: refine error message Chengwen Feng
2024-03-18  9:18   ` [PATCH v3 2/6] argparse: remove dead code Chengwen Feng
2024-03-18  9:18   ` [PATCH v3 3/6] argparse: replace flag enum with marco Chengwen Feng
2024-03-18  9:18   ` [PATCH v3 4/6] argparse: fix argument flags operate as uint32 type Chengwen Feng
2024-03-18  9:38     ` Thomas Monjalon
2024-03-18 11:24       ` fengchengwen
2024-03-18  9:18   ` [PATCH v3 5/6] test/argparse: refine testcases Chengwen Feng
2024-03-18  9:18   ` [PATCH v3 6/6] argparse: fix doc don't display two hyphens Chengwen Feng
2024-03-18 11:18 ` [PATCH v4 0/6] refine argparse library Chengwen Feng
2024-03-18 11:18   ` Chengwen Feng [this message]
2024-03-18 11:18   ` [PATCH v4 2/6] argparse: remove dead code Chengwen Feng
2024-03-18 11:18   ` [PATCH v4 3/6] argparse: replace flag enum with marco Chengwen Feng
2024-03-18 11:18   ` [PATCH v4 4/6] argparse: fix argument flags operate as uint32 type Chengwen Feng
2024-03-18 11:18   ` [PATCH v4 5/6] test/argparse: refine testcases Chengwen Feng
2024-03-18 11:18   ` [PATCH v4 6/6] argparse: fix doc don't display two hyphens Chengwen Feng
2024-03-21 17:27   ` [PATCH v4 0/6] refine argparse library Thomas Monjalon
2024-03-22  1:24     ` fengchengwen
2024-05-08  9:10     ` fengchengwen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240318111838.16991-2-fengchengwen@huawei.com \
    --to=fengchengwen@huawei.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).