From: Eric Sandeen <sandeen@redhat.com>
To: kreijack@inwind.it, Wang Shilong <wangshilong1991@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/4] Btrfs-progs: new helper to parse string to u64 for btrfs
Date: Wed, 19 Feb 2014 11:23:29 -0600 [thread overview]
Message-ID: <5304E891.8040606@redhat.com> (raw)
In-Reply-To: <5304DC5B.9050707@inwind.it>
On 2/19/14, 10:31 AM, Goffredo Baroncelli wrote:
...
> The error message says that the value is out of range. But doesn't tell which
> is the parameter involved.
> If you have a command which has several arguments, and the user pass a string
> instead of a number, the error returned doesn't tell which argument is wrong.
> This is the reason of my complaint.
>
> At least add a fourth parameter which contains the name of the parameter
> parsed in order to improve the error message.
>
> I.E.
>
> subvol_id = btrfs_strtoull(argv[i], 10, "subvolume ID");
>
> If the user pass a path instead of a number the error message would be
>
> ERROR: xxxx is not a valid unsigned long long integer for the parameter 'subvolume ID'.
>
> Or something like that.
I'm not so sure that this is needed. Adding it makes the code a little more complicated,
and requires each caller to send in a string which may get out of sync with the actual
argument name (or the manpage, or the help/usage text).
The user has *just* typed it in, so it won't be too hard to see which one
was wrong even without naming the parameter, i.e. -
# btrfs foo-command 12345 0 123notanumber
Error: 123notanumber is not a valid numeric value
or
# btrfs baz-command 0xFFFFFFFFFFFFFFFF 12345 0
Error: numeric value 0xFFFFFFFFFFFFFFFF is too large.
would probably suffice, without bothering to name the parameter.
I'd also suggest not referring to "unsigned long long" or "out of range" which
might not mean much to people who aren't programmers; "not a valid value"
or "too large" might be clearer.
Also, what if someone enters a negative number? Right now it happily
accepts it and converts it to an unsigned value:
# ./test-64bit -123
Parsed as 18446744073709551493
but an inadvertent negative sign might lead to highly unexpected results.
Just my $0.02.
-Eric
next prev parent reply other threads:[~2014-02-19 17:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-19 11:17 [PATCH 0/4] Btrfs-progs: cleanups: new helper for parsing string to u64 Wang Shilong
2014-02-19 11:17 ` [PATCH 1/4] Btrfs-progs: new helper to parse string to u64 for btrfs Wang Shilong
2014-02-19 14:46 ` Stefan Behrens
2014-02-19 14:59 ` Wang Shilong
2014-02-19 15:47 ` Goffredo Baroncelli
2014-02-19 16:08 ` Wang Shilong
2014-02-19 16:31 ` Goffredo Baroncelli
2014-02-19 16:43 ` Wang Shilong
2014-02-19 17:23 ` Eric Sandeen [this message]
2014-02-20 0:48 ` Wang Shilong
2014-02-20 16:42 ` David Sterba
2014-02-19 11:17 ` [PATCH 2/4] Btrfs-progs: switch to btrfs_strtoull() part1 Wang Shilong
2014-02-19 11:17 ` [PATCH 3/4] Btrfs-progs: switch to btrfs_strtoull() part2 Wang Shilong
2014-02-19 11:17 ` [PATCH 4/4] Btrfs-progs: switch to btrfs_strtoull() part3 Wang Shilong
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=5304E891.8040606@redhat.com \
--to=sandeen@redhat.com \
--cc=kreijack@inwind.it \
--cc=linux-btrfs@vger.kernel.org \
--cc=wangshilong1991@gmail.com \
/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).