[Qemu-devel] [PATCH v3 36/38] block: Clean up bdrv_img_create()'s error reporting

Markus Armbruster posted 38 patches 7 years ago
There is a newer version of this series
[Qemu-devel] [PATCH v3 36/38] block: Clean up bdrv_img_create()'s error reporting
Posted by Markus Armbruster 7 years ago
bdrv_img_create() takes an Error ** argument and uses it in the
conventional way, except for one place: when qemu_opts_do_parse()
fails, it first reports its error to stderr or the HMP monitor with
error_report_err(), then error_setg()'s a generic error.

When the caller reports that second error similarly, this produces two
consecutive error messages on stderr or the HMP monitor.

When the caller does something else with it, such as send it via QMP,
the first error still goes to stderr or the HMP monitor.  Fortunately,
no such caller exists.

Simply use the first error as is.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/block.c b/block.c
index 5d51419d21..08d64cdc61 100644
--- a/block.c
+++ b/block.c
@@ -4803,9 +4803,6 @@ void bdrv_img_create(const char *filename, const char *fmt,
     if (options) {
         qemu_opts_do_parse(opts, options, NULL, &local_err);
         if (local_err) {
-            error_report_err(local_err);
-            local_err = NULL;
-            error_setg(errp, "Invalid options for file format '%s'", fmt);
             goto out;
         }
     }
-- 
2.17.1


Re: [Qemu-devel] [PATCH v3 36/38] block: Clean up bdrv_img_create()'s error reporting
Posted by Eric Blake 7 years ago
On 10/16/18 12:41 PM, Markus Armbruster wrote:
> bdrv_img_create() takes an Error ** argument and uses it in the
> conventional way, except for one place: when qemu_opts_do_parse()
> fails, it first reports its error to stderr or the HMP monitor with
> error_report_err(), then error_setg()'s a generic error.
> 
> When the caller reports that second error similarly, this produces two
> consecutive error messages on stderr or the HMP monitor.
> 
> When the caller does something else with it, such as send it via QMP,
> the first error still goes to stderr or the HMP monitor.  Fortunately,
> no such caller exists.
> 
> Simply use the first error as is.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>   block.c | 3 ---
>   1 file changed, 3 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org