From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHkKu-00033d-Dj for qemu-devel@nongnu.org; Mon, 07 Dec 2009 15:37:36 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHkKn-0002ym-E6 for qemu-devel@nongnu.org; Mon, 07 Dec 2009 15:37:33 -0500 Received: from [199.232.76.173] (port=46530 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHkKn-0002yR-6z for qemu-devel@nongnu.org; Mon, 07 Dec 2009 15:37:29 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:47587) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NHkKl-0001Sv-Td for qemu-devel@nongnu.org; Mon, 07 Dec 2009 15:37:28 -0500 Received: from crossbow.pond.sub.org (pD9E38C82.dip.t-dialin.net [217.227.140.130]) by oxygen.pond.sub.org (Postfix) with ESMTPA id AC931276D5F for ; Mon, 7 Dec 2009 21:37:20 +0100 (CET) From: Markus Armbruster Date: Mon, 7 Dec 2009 21:37:16 +0100 Message-Id: <1260218236-22143-19-git-send-email-armbru@redhat.com> In-Reply-To: <1260218236-22143-1-git-send-email-armbru@redhat.com> References: <1260218236-22143-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lcapitulino@redhat.com Signed-off-by: Markus Armbruster --- QMP/qmp-spec.txt | 5 ++++- monitor.c | 1 + qerror.c | 21 ++++++++++++++++----- qerror.h | 2 ++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/QMP/qmp-spec.txt b/QMP/qmp-spec.txt index 8429789..1cbd21c 100644 --- a/QMP/qmp-spec.txt +++ b/QMP/qmp-spec.txt @@ -102,13 +102,16 @@ completed because of an error condition. The format is: -{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value } Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client) diff --git a/monitor.c b/monitor.c index 0bcffbe..4ad1b5e 100644 --- a/monitor.c +++ b/monitor.c @@ -305,6 +305,7 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data) } } else { /* error response */ + qdict_put(mon->error->error, "desc", qerror_human(mon->error)); qdict_put(qmp, "error", mon->error->error); QINCREF(mon->error->error); QDECREF(mon->error); diff --git a/qerror.c b/qerror.c index 8ffe4f6..5f8fc5d 100644 --- a/qerror.c +++ b/qerror.c @@ -283,13 +283,11 @@ static const char *append_field(QString *outstr, const QError *qerror, } /** - * qerror_print(): Print QError data + * qerror_human(): Format QError data into human-readable string. * - * This function will print the member 'desc' of the specified QError object, - * it uses qemu_error() for this, so that the output is routed to the right - * place (ie. stderr or Monitor's device). + * Formats according to member 'desc' of the specified QError object. */ -void qerror_print(const QError *qerror) +QString *qerror_human(const QError *qerror) { const char *p; QString *qstring; @@ -309,6 +307,19 @@ void qerror_print(const QError *qerror) } } + return qstring; +} + +/** + * qerror_print(): Print QError data + * + * This function will print the member 'desc' of the specified QError object, + * it uses qemu_error() for this, so that the output is routed to the right + * place (ie. stderr or Monitor's device). + */ +void qerror_print(const QError *qerror) +{ + QString *qstring = qerror_human(qerror); qemu_error("%s\n", qstring_get_str(qstring)); QDECREF(qstring); } diff --git a/qerror.h b/qerror.h index 9462d5c..09e32b9 100644 --- a/qerror.h +++ b/qerror.h @@ -13,6 +13,7 @@ #define QERROR_H #include "qdict.h" +#include "qstring.h" #include typedef struct QErrorStringTable { @@ -32,6 +33,7 @@ typedef struct QError { QError *qerror_new(void); QError *qerror_from_info(const char *file, int linenr, const char *func, const char *fmt, va_list *va); +QString *qerror_human(const QError *qerror); void qerror_print(const QError *qerror); QError *qobject_to_qerror(const QObject *obj); -- 1.6.2.5