Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mxpws-0004UT-A2 for qemu-devel@nongnu.org; Tue, 13 Oct 2009 18:34:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mxpwm-0004TW-PQ for qemu-devel@nongnu.org; Tue, 13 Oct 2009 18:34:28 -0400 Received: from [199.232.76.173] (port=43505 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mxpwm-0004TS-GG for qemu-devel@nongnu.org; Tue, 13 Oct 2009 18:34:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61190) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mxpwm-000327-19 for qemu-devel@nongnu.org; Tue, 13 Oct 2009 18:34:24 -0400 Subject: Re: [Qemu-devel] [PATCH 7/9] qdev: Use QError for not found error References: <1255453026-18637-1-git-send-email-lcapitulino@redhat.com> <1255453026-18637-8-git-send-email-lcapitulino@redhat.com> From: Markus Armbruster Date: Wed, 14 Oct 2009 00:34:21 +0200 In-Reply-To: <1255453026-18637-8-git-send-email-lcapitulino@redhat.com> (Luiz Capitulino's message of "Tue\, 13 Oct 2009 13\:57\:04 -0300") Message-ID: <877huy6hzm.fsf@pike.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, kraxel@redhat.com Luiz Capitulino writes: > Signed-off-by: Luiz Capitulino > --- > 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 we need the structure, then it's just a price we have to pay. Do we need it? In the example above, it gets us two pieces of information in addition to the "monitor command failed" bit: the error code, which tells us the exact kind of failure, and a data object to go with the error code, in this case containing the name of the device. Now let's look at errors from the client's perspective. Clients need to classify errors to figure out how to respond to them. Something like client error (i.e. your command was stupid, and trying again will be just as stupid), permanent server error (it wasn't stupid, but I can't do it for you), transient server error (I couldn't do it for you, but trying again later could help). Some classical protocols (HTTP, FTP) provide error class (they cleverly encode it into the error code). This gives clients a chance to sanely handle errors they don't know. Even with error class figured out, clients may still be interested in the exact error code, at least in some cases. They may also be interested in a human readable description of the error, to present to their human users. Some classical protocols provide that in addition to an error code. This gives clients a chance to sanely report errors they don't know to human users. I suspect that the additional error data is the error's least interesting part most of the time. When we get QERR_QDEV_NFOUND, I figure it's usually clear what device we were trying to find. But these are just my educated guesses. I'd love to hear what folks involved with actual clients have to say. Anyone from libvirt?