* [Qemu-trivial] [PATCH] qemu-img: fix error messages emitted by img_open()
@ 2016-07-21 8:41 Reda Sallahi
2016-07-21 9:07 ` Stefan Hajnoczi
0 siblings, 1 reply; 4+ messages in thread
From: Reda Sallahi @ 2016-07-21 8:41 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-block, Kevin Wolf, Max Reitz, Fam Zheng, Stefan Hajnoczi,
qemu-trivial, Reda Sallahi
img_open_file() and img_open_opts() were printing error messages with a
duplicate part because of a wrong use of error_reportf_err() (e.g.
qemu-img: Could not open 'foo': Could not open 'foo': No such file or directory)
This change uses error_report_err() instead to eliminate the duplicate part.
Signed-off-by: Reda Sallahi <fullmanet@gmail.com>
---
qemu-img.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 2e40e1f..dc6652d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -268,7 +268,7 @@ static BlockBackend *img_open_opts(const char *optstr,
options = qemu_opts_to_qdict(opts, NULL);
blk = blk_new_open(NULL, NULL, options, flags, &local_err);
if (!blk) {
- error_reportf_err(local_err, "Could not open '%s': ", optstr);
+ error_report_err(local_err);
return NULL;
}
blk_set_enable_write_cache(blk, !writethrough);
@@ -295,7 +295,7 @@ static BlockBackend *img_open_file(const char *filename,
blk = blk_new_open(filename, NULL, options, flags, &local_err);
if (!blk) {
- error_reportf_err(local_err, "Could not open '%s': ", filename);
+ error_report(local_err);
return NULL;
}
blk_set_enable_write_cache(blk, !writethrough);
--
2.9.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-trivial] [PATCH] qemu-img: fix error messages emitted by img_open()
2016-07-21 8:41 [Qemu-trivial] [PATCH] qemu-img: fix error messages emitted by img_open() Reda Sallahi
@ 2016-07-21 9:07 ` Stefan Hajnoczi
2016-07-25 15:58 ` [Qemu-trivial] [Qemu-devel] " Markus Armbruster
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2016-07-21 9:07 UTC (permalink / raw)
To: Reda Sallahi
Cc: qemu-devel, qemu-block, Kevin Wolf, Max Reitz, Fam Zheng,
qemu-trivial
[-- Attachment #1: Type: text/plain, Size: 1867 bytes --]
On Thu, Jul 21, 2016 at 10:41:53AM +0200, Reda Sallahi wrote:
> img_open_file() and img_open_opts() were printing error messages with a
> duplicate part because of a wrong use of error_reportf_err() (e.g.
> qemu-img: Could not open 'foo': Could not open 'foo': No such file or directory)
>
> This change uses error_report_err() instead to eliminate the duplicate part.
>
> Signed-off-by: Reda Sallahi <fullmanet@gmail.com>
> ---
> qemu-img.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 2e40e1f..dc6652d 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -268,7 +268,7 @@ static BlockBackend *img_open_opts(const char *optstr,
> options = qemu_opts_to_qdict(opts, NULL);
> blk = blk_new_open(NULL, NULL, options, flags, &local_err);
> if (!blk) {
> - error_reportf_err(local_err, "Could not open '%s': ", optstr);
> + error_report_err(local_err);
> return NULL;
> }
> blk_set_enable_write_cache(blk, !writethrough);
> @@ -295,7 +295,7 @@ static BlockBackend *img_open_file(const char *filename,
>
> blk = blk_new_open(filename, NULL, options, flags, &local_err);
> if (!blk) {
> - error_reportf_err(local_err, "Could not open '%s': ", filename);
> + error_report(local_err);
> return NULL;
> }
> blk_set_enable_write_cache(blk, !writethrough);
The duplication happens in the "Could not open 'foo'" case, but other
error cases do not include the filename in the error message.
We would lose information in those error cases since the filename is no
longer included by qemu-img.c in the error message.
I'm not aware of a clean way to distinguish Error objects. Maybe
someone else can suggest one. Otherwise it may be best to leave the
code as it is.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-trivial] [Qemu-devel] [PATCH] qemu-img: fix error messages emitted by img_open()
2016-07-21 9:07 ` Stefan Hajnoczi
@ 2016-07-25 15:58 ` Markus Armbruster
2016-07-26 13:07 ` Stefan Hajnoczi
0 siblings, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2016-07-25 15:58 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: Reda Sallahi, Kevin Wolf, Fam Zheng, qemu-block, qemu-trivial,
qemu-devel, Max Reitz
Stefan Hajnoczi <stefanha@redhat.com> writes:
> On Thu, Jul 21, 2016 at 10:41:53AM +0200, Reda Sallahi wrote:
>> img_open_file() and img_open_opts() were printing error messages with a
>> duplicate part because of a wrong use of error_reportf_err() (e.g.
>> qemu-img: Could not open 'foo': Could not open 'foo': No such file or directory)
>>
>> This change uses error_report_err() instead to eliminate the duplicate part.
>>
>> Signed-off-by: Reda Sallahi <fullmanet@gmail.com>
>> ---
>> qemu-img.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/qemu-img.c b/qemu-img.c
>> index 2e40e1f..dc6652d 100644
>> --- a/qemu-img.c
>> +++ b/qemu-img.c
>> @@ -268,7 +268,7 @@ static BlockBackend *img_open_opts(const char *optstr,
>> options = qemu_opts_to_qdict(opts, NULL);
>> blk = blk_new_open(NULL, NULL, options, flags, &local_err);
>> if (!blk) {
>> - error_reportf_err(local_err, "Could not open '%s': ", optstr);
>> + error_report_err(local_err);
>> return NULL;
>> }
>> blk_set_enable_write_cache(blk, !writethrough);
>> @@ -295,7 +295,7 @@ static BlockBackend *img_open_file(const char *filename,
>>
>> blk = blk_new_open(filename, NULL, options, flags, &local_err);
>> if (!blk) {
>> - error_reportf_err(local_err, "Could not open '%s': ", filename);
>> + error_report(local_err);
>> return NULL;
>> }
>> blk_set_enable_write_cache(blk, !writethrough);
>
> The duplication happens in the "Could not open 'foo'" case, but other
> error cases do not include the filename in the error message.
>
> We would lose information in those error cases since the filename is no
> longer included by qemu-img.c in the error message.
Could you give an example of such an information loss?
> I'm not aware of a clean way to distinguish Error objects. Maybe
> someone else can suggest one. Otherwise it may be best to leave the
> code as it is.
If you need to distinguish different kinds of errors to conditionally
rewrite the error message so it makes actual sense, chances are the
error messages that need the rewriting should be improved instead.
A more legitimate case is when a caller needs to handle different errors
differently. Doesn't occur all that often.
There are two techniques for callers to distinguish different kinds of
Errors:
* ErrorClass, use error_get_class() to retrieve it. This is actually a
remnant of the failed "rich" error object idea. Almost always
ERROR_CLASS_GENERIC_ERROR, so this is unlikely to help.
* Error code separate from the Error object, e.g. the function returns
-errno in addition to an Error object.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-trivial] [Qemu-devel] [PATCH] qemu-img: fix error messages emitted by img_open()
2016-07-25 15:58 ` [Qemu-trivial] [Qemu-devel] " Markus Armbruster
@ 2016-07-26 13:07 ` Stefan Hajnoczi
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2016-07-26 13:07 UTC (permalink / raw)
To: Markus Armbruster
Cc: Reda Sallahi, Kevin Wolf, Fam Zheng, qemu-block, qemu-trivial,
qemu-devel, Max Reitz
[-- Attachment #1: Type: text/plain, Size: 3320 bytes --]
On Mon, Jul 25, 2016 at 05:58:54PM +0200, Markus Armbruster wrote:
> Stefan Hajnoczi <stefanha@redhat.com> writes:
>
> > On Thu, Jul 21, 2016 at 10:41:53AM +0200, Reda Sallahi wrote:
> >> img_open_file() and img_open_opts() were printing error messages with a
> >> duplicate part because of a wrong use of error_reportf_err() (e.g.
> >> qemu-img: Could not open 'foo': Could not open 'foo': No such file or directory)
> >>
> >> This change uses error_report_err() instead to eliminate the duplicate part.
> >>
> >> Signed-off-by: Reda Sallahi <fullmanet@gmail.com>
> >> ---
> >> qemu-img.c | 4 ++--
> >> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/qemu-img.c b/qemu-img.c
> >> index 2e40e1f..dc6652d 100644
> >> --- a/qemu-img.c
> >> +++ b/qemu-img.c
> >> @@ -268,7 +268,7 @@ static BlockBackend *img_open_opts(const char *optstr,
> >> options = qemu_opts_to_qdict(opts, NULL);
> >> blk = blk_new_open(NULL, NULL, options, flags, &local_err);
> >> if (!blk) {
> >> - error_reportf_err(local_err, "Could not open '%s': ", optstr);
> >> + error_report_err(local_err);
> >> return NULL;
> >> }
> >> blk_set_enable_write_cache(blk, !writethrough);
> >> @@ -295,7 +295,7 @@ static BlockBackend *img_open_file(const char *filename,
> >>
> >> blk = blk_new_open(filename, NULL, options, flags, &local_err);
> >> if (!blk) {
> >> - error_reportf_err(local_err, "Could not open '%s': ", filename);
> >> + error_report(local_err);
> >> return NULL;
> >> }
> >> blk_set_enable_write_cache(blk, !writethrough);
> >
> > The duplication happens in the "Could not open 'foo'" case, but other
> > error cases do not include the filename in the error message.
> >
> > We would lose information in those error cases since the filename is no
> > longer included by qemu-img.c in the error message.
>
> Could you give an example of such an information loss?
The issue is that while this patch eliminates duplication in:
qemu-img: Could not open 'foo': Could not open 'foo': No such file or directory
It loses the name from:
qemu-img: Driver 'bar' is not whitelisted
or any other error message in block.c that doesn't include the filename.
This is probably the reason why qemu-img.c prepends "Could not open
'%s'".
> > I'm not aware of a clean way to distinguish Error objects. Maybe
> > someone else can suggest one. Otherwise it may be best to leave the
> > code as it is.
>
> If you need to distinguish different kinds of errors to conditionally
> rewrite the error message so it makes actual sense, chances are the
> error messages that need the rewriting should be improved instead.
>
> A more legitimate case is when a caller needs to handle different errors
> differently. Doesn't occur all that often.
>
> There are two techniques for callers to distinguish different kinds of
> Errors:
>
> * ErrorClass, use error_get_class() to retrieve it. This is actually a
> remnant of the failed "rich" error object idea. Almost always
> ERROR_CLASS_GENERIC_ERROR, so this is unlikely to help.
>
> * Error code separate from the Error object, e.g. the function returns
> -errno in addition to an Error object.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-07-26 13:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-21 8:41 [Qemu-trivial] [PATCH] qemu-img: fix error messages emitted by img_open() Reda Sallahi
2016-07-21 9:07 ` Stefan Hajnoczi
2016-07-25 15:58 ` [Qemu-trivial] [Qemu-devel] " Markus Armbruster
2016-07-26 13:07 ` Stefan Hajnoczi
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).