From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: lcapitulino@redhat.com
Subject: [Qemu-devel] [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
Date: Mon, 7 Dec 2009 21:37:16 +0100 [thread overview]
Message-ID: <1260218236-22143-19-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1260218236-22143-1-git-send-email-armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
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 <stdarg.h>
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
next prev parent reply other threads:[~2009-12-07 20:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-07 20:36 [Qemu-devel] [FOR 0.12 PATCH 00/18] QError conversions and more Markus Armbruster
2009-12-07 20:36 ` [Qemu-devel] [FOR 0.12 PATCH 01/18] QError: new class for device encrypted errors Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 02/18] monitor: do_cont(): Don't ask for passwords Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 03/18] monitor: Fix double-prompt after "change vnc passwd BLA" Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 04/18] QError: Put error definitions in alphabetical order Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 05/18] QError: New QERR_DEVICE_LOCKED Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 06/18] QError: New QERR_DEVICE_NOT_REMOVABLE Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 07/18] monitor: convert do_eject() to QError Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 08/18] QError: New QERR_INVALID_BLOCK_FORMAT Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 09/18] QError: New QERR_SET_PASSWD_FAILED Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 10/18] QError: New QERR_VNC_SERVER_FAILED Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 11/18] monitor: convert do_change() to QObject, QError Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 12/18] QError: New QERR_FD_NOT_FOUND Markus Armbruster
2009-12-08 11:51 ` [Qemu-devel] " Luiz Capitulino
2009-12-08 12:25 ` Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 13/18] monitor: convert do_closefd() to QError Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 14/18] QError: New QERR_FD_NOT_SUPPLIED Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 15/18] New QERR_INVALID_PARAMETER Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 16/18] QError: New QERR_TOO_MANY_FILES Markus Armbruster
2009-12-07 20:37 ` [Qemu-devel] [FOR 0.12 PATCH 17/18] monitor: convert do_getfd() to QError Markus Armbruster
2009-12-07 20:37 ` Markus Armbruster [this message]
2009-12-08 12:11 ` [Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response Luiz Capitulino
2009-12-08 12:25 ` Daniel P. Berrange
2009-12-08 14:11 ` Luiz Capitulino
2009-12-08 14:50 ` Markus Armbruster
2009-12-08 12:38 ` Paolo Bonzini
2009-12-08 12:57 ` Markus Armbruster
2009-12-08 12:48 ` Markus Armbruster
2009-12-08 13:18 ` Anthony Liguori
2009-12-08 14:41 ` Luiz Capitulino
2009-12-08 11:49 ` [Qemu-devel] Re: [FOR 0.12 PATCH 00/18] QError conversions and more Luiz Capitulino
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=1260218236-22143-19-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=lcapitulino@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).