[libvirt] [PATCH 1/3] virsh: Improve error message on integer value parsing failure.
Michal Privoznik
mprivozn at redhat.com
Mon May 18 09:17:34 UTC 2015
On 15.05.2015 18:14, Andrea Bolognani wrote:
> Replace more than 30 ad-hoc error messages with a single, generic one
> that contains the name of the option being processed and some hints
> to help the user understand what could have gone wrong.
>
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1207043
> ---
> tests/vcpupin | 4 +-
> tools/virsh-domain-monitor.c | 10 +++--
> tools/virsh-domain.c | 102 ++++++++++++++++++++++++++++++++-----------
> tools/virsh-host.c | 44 ++++++++++++++-----
> tools/virsh-interface.c | 4 +-
> tools/virsh-network.c | 4 +-
> tools/virsh-volume.c | 16 +++++--
> 7 files changed, 135 insertions(+), 49 deletions(-)
>
> diff --git a/tests/vcpupin b/tests/vcpupin
> index cd09145..ab0d38f 100755
> --- a/tests/vcpupin
> +++ b/tests/vcpupin
> @@ -34,7 +34,7 @@ fail=0
> $abs_top_builddir/tools/virsh --connect test:///default vcpupin test a 0,1 > out 2>&1
> test $? = 1 || fail=1
> cat <<\EOF > exp || fail=1
> -error: vcpupin: Invalid vCPU number.
> +error: Numeric value for <vcpu> option is malformed or out of range
>
> EOF
> compare exp out || fail=1
> @@ -52,7 +52,7 @@ compare exp out || fail=1
> $abs_top_builddir/tools/virsh --connect test:///default vcpupin test -100 0,1 > out 2>&1
> test $? = 1 || fail=1
> cat <<\EOF > exp || fail=1
> -error: vcpupin: Invalid vCPU number.
> +error: Numeric value for <vcpu> option is malformed or out of range
>
> EOF
> compare exp out || fail=1
> diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
> index 91c57e2..51276d3 100644
> --- a/tools/virsh-domain-monitor.c
> +++ b/tools/virsh-domain-monitor.c
> @@ -341,8 +341,9 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
> * This is not really an unsigned long, but it
> */
> if ((rv = vshCommandOptInt(cmd, "period", &period)) < 0) {
> - vshError(ctl, "%s",
> - _("Unable to parse integer parameter."));
> + vshError(ctl,
> + _("Numeric value for <%s> option is malformed or out of range"),
> + "period");
I wonder if we can make all vshCommandOpt*() throw an error now that we
have a generic error message. For all the places where no error is
reported - we can invent vshCommandOpt*Quiet(). Just follow the same
pattern we have for virAsprintf().
Michal
More information about the libvir-list
mailing list