From: Luiz Capitulino <lcapitulino@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: aliguori@us.ibm.com, kraxel@redhat.com,
Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 7/9] qdev: Use QError for not found error
Date: Wed, 14 Oct 2009 13:42:35 -0300 [thread overview]
Message-ID: <20091014134235.450f7b56@doriath> (raw)
In-Reply-To: <4AD5D245.9050705@redhat.com>
On Wed, 14 Oct 2009 15:29:41 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 10/14/2009 12:34 AM, Markus Armbruster wrote:
> > Luiz Capitulino<lcapitulino@redhat.com> writes:
> >
> >> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> >> ---
> >> hw/qdev.c | 4 ++--
> >> 1 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/hw/qdev.c b/hw/qdev.c
> >> index 906e897..3ce48f7 100644
> >> --- a/hw/qdev.c
> >> +++ b/hw/qdev.c
> >> @@ -28,6 +28,7 @@
> >> #include "net.h"
> >> #include "qdev.h"
> >> #include "sysemu.h"
> >> +#include "qerror.h"
> >> #include "monitor.h"
> >>
> >> static int qdev_hotplug = 0;
> >> @@ -176,8 +177,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> >> /* find driver */
> >> info = qdev_find_info(NULL, driver);
> >> if (!info) {
> >> - qemu_error("Device \"%s\" not found. Try -device '?' for a list.\n",
> >> - driver);
> >> + qemu_error_structed(QERR_QDEV_NFOUND, "{ s: s }", "name", driver);
> >> return NULL;
> >> }
> >> if (info->no_user) {
> >
> > And here we pay the price for structured error objects: reporting an
> > error becomes more difficult. The harder you make reporting errors, the
> > fewer errors get caught and reported. Also, the result is harder to
> > read.
>
> If you count also the new code in 6/9, reporting an error definitely
> becomes harder. Finding a middle ground would be great, and I think
> that the right solution is to put as many things as possible in a single
> place. For example:
>
> 1) there is a lot of code that is duplicated in every occurrence of an
> error. One possibility to avoid this, would be to use a more
> printf-like syntax for qemu_object_from_va, for example one of these:
>
> .... "{ name: %s }", driver);
> .... "{ 'name': %s }", driver);
>
> Then you can move the first argument to the error table:
>
> + .code = QERR_QDEV_NFOUND,
> + .desc = "device not found",
> + .keys = "{ name: %s }"
>
> so that the qemu_error_structed call looks like
>
> qemu_error_structed (QERR_QDEV_NFOUND, driver);
>
> 2) do we need full flexibility of a function for printing errors? What
> about adding a print-from-qobject function, so that you could replace
> qerror_table[].user_print with a string like
>
> .formatted_print = "Device \"%{name}\" not found. Try -device"
> " '?' for a list."
I like both, but I see them as future improvements.
> 3) I don't think this technique is used in qemu, but what about putting
> all errors in a header file like
We have qemu-monitor.hx, which is something like it.
> QEMU_ERROR(QERR_DEV_NFOUND,
> "device not found",
> whatever);
>
> Then you can use the header file to generate both the enum and the error
> table:
>
> typedef enum QErrorCode {
> #define QEMU_ERROR(code_, ...) code_,
> #include "qemu.def"
> #undef QEMU_ERROR
> } QErrorCode;
>
> ...
>
> static QErrorTable qerror_table[] = {
> #define QEMU_ERROR(code_, desc_, data_) \
> { .code = (code_), .desc = (desc_), .data = (data_),
> #include "qemu-error.def"
> #undef QEMU_ERROR
> };
>
> This has the disadvantage of not allowing usage of designated initializers.
Not sure if it really helps.
next prev parent reply other threads:[~2009-10-14 16:42 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-13 16:56 [Qemu-devel] [PATCH v0 0/9] QError Luiz Capitulino
2009-10-13 16:56 ` [Qemu-devel] [PATCH 1/9] QDict: Introduce qdict_iter() Luiz Capitulino
2009-10-13 16:56 ` [Qemu-devel] [PATCH 2/9] check-qdict: Add test for qdict_iter() Luiz Capitulino
2009-10-13 16:57 ` [Qemu-devel] [PATCH 3/9] qmisc: Introduce qobject_from_va() Luiz Capitulino
2009-10-13 21:52 ` Markus Armbruster
2009-10-14 13:40 ` Luiz Capitulino
2009-10-14 14:27 ` [Qemu-devel] " Paolo Bonzini
2009-10-13 16:57 ` [Qemu-devel] [PATCH 4/9] Introduce QError Luiz Capitulino
2009-10-13 16:57 ` [Qemu-devel] [PATCH 5/9] monitor: QError support Luiz Capitulino
2009-10-13 21:59 ` Markus Armbruster
2009-10-14 13:14 ` [Qemu-devel] " Paolo Bonzini
2009-10-14 14:07 ` Markus Armbruster
2009-10-13 16:57 ` [Qemu-devel] [PATCH 6/9] QError: Add qdev not found error Luiz Capitulino
2009-10-14 23:02 ` Hollis Blanchard
2009-10-15 13:34 ` Luiz Capitulino
2009-10-15 17:16 ` Hollis Blanchard
2009-10-15 17:52 ` Luiz Capitulino
2009-10-15 18:13 ` Hollis Blanchard
2009-10-15 19:08 ` Luiz Capitulino
2009-10-15 20:13 ` Hollis Blanchard
2009-10-15 20:57 ` Anthony Liguori
2009-10-15 21:18 ` Hollis Blanchard
2009-10-15 21:27 ` Anthony Liguori
2009-10-15 22:44 ` Hollis Blanchard
2009-10-16 8:06 ` [Qemu-devel] " Paolo Bonzini
2009-10-16 13:05 ` Luiz Capitulino
2009-10-19 10:25 ` Daniel P. Berrange
2009-10-19 12:28 ` Luiz Capitulino
2009-10-19 12:42 ` Daniel P. Berrange
2009-10-16 13:39 ` Anthony Liguori
2009-10-18 4:25 ` [Qemu-devel] " Jamie Lokier
2009-10-18 12:17 ` [Qemu-devel] " Paolo Bonzini
2009-10-19 16:50 ` Hollis Blanchard
2009-10-19 21:16 ` Paolo Bonzini
2009-10-16 7:30 ` [Qemu-devel] " Gerd Hoffmann
2009-10-16 12:39 ` Luiz Capitulino
2009-10-16 13:34 ` [Qemu-devel] " Paolo Bonzini
2009-10-16 13:37 ` [Qemu-devel] " Anthony Liguori
2009-10-16 14:17 ` Luiz Capitulino
2009-10-16 17:28 ` [Qemu-devel] " Paolo Bonzini
2009-10-16 17:47 ` Anthony Liguori
2009-10-16 8:02 ` Paolo Bonzini
2009-10-18 4:28 ` Jamie Lokier
2009-10-18 4:34 ` Jamie Lokier
2009-10-13 16:57 ` [Qemu-devel] [PATCH 7/9] qdev: Use QError for " Luiz Capitulino
2009-10-13 22:34 ` Markus Armbruster
2009-10-14 13:29 ` [Qemu-devel] " Paolo Bonzini
2009-10-14 16:42 ` Luiz Capitulino [this message]
2009-10-14 14:51 ` [Qemu-devel] " Luiz Capitulino
2009-10-19 10:12 ` Daniel P. Berrange
2009-10-19 10:40 ` Gerd Hoffmann
2009-10-19 10:47 ` Daniel P. Berrange
2009-10-19 11:22 ` [Qemu-devel] " Paolo Bonzini
2009-10-19 14:00 ` [Qemu-devel] " Anthony Liguori
2009-10-19 15:21 ` Daniel P. Berrange
2009-10-19 15:27 ` Anthony Liguori
2009-10-19 15:39 ` Daniel P. Berrange
2009-10-13 16:57 ` [Qemu-devel] [PATCH 8/9] QError: Add do_info_balloon() errors Luiz Capitulino
2009-10-13 16:57 ` [Qemu-devel] [PATCH 9/9] monitor: do_info_balloon(): use QError Luiz Capitulino
2009-10-15 19:24 ` [Qemu-devel] [PATCH v0 0/9] QError Anthony Liguori
2009-10-15 19:37 ` Luiz Capitulino
2009-10-19 13:13 ` Markus Armbruster
2009-10-19 14:11 ` Anthony Liguori
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=20091014134235.450f7b56@doriath \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).