mirror of https://github.com/xqemu/xqemu.git
QMP: add human-readable description to error response
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
7cdfcfe18f
commit
77e595e7c6
|
@ -102,13 +102,16 @@ completed because of an error condition.
|
||||||
|
|
||||||
The format is:
|
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,
|
Where,
|
||||||
|
|
||||||
- The "class" member contains the error class name (eg. "ServiceUnavailable")
|
- The "class" member contains the error class name (eg. "ServiceUnavailable")
|
||||||
- The "data" member contains specific error data and is defined in a
|
- 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
|
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 "id" member contains the transaction identification associated with
|
||||||
the command execution (if issued by the Client)
|
the command execution (if issued by the Client)
|
||||||
|
|
||||||
|
|
|
@ -305,6 +305,7 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* error response */
|
/* error response */
|
||||||
|
qdict_put(mon->error->error, "desc", qerror_human(mon->error));
|
||||||
qdict_put(qmp, "error", mon->error->error);
|
qdict_put(qmp, "error", mon->error->error);
|
||||||
QINCREF(mon->error->error);
|
QINCREF(mon->error->error);
|
||||||
QDECREF(mon->error);
|
QDECREF(mon->error);
|
||||||
|
|
21
qerror.c
21
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,
|
* Formats according to 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 *qerror_human(const QError *qerror)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
QString *qstring;
|
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));
|
qemu_error("%s\n", qstring_get_str(qstring));
|
||||||
QDECREF(qstring);
|
QDECREF(qstring);
|
||||||
}
|
}
|
||||||
|
|
2
qerror.h
2
qerror.h
|
@ -13,6 +13,7 @@
|
||||||
#define QERROR_H
|
#define QERROR_H
|
||||||
|
|
||||||
#include "qdict.h"
|
#include "qdict.h"
|
||||||
|
#include "qstring.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
typedef struct QErrorStringTable {
|
typedef struct QErrorStringTable {
|
||||||
|
@ -32,6 +33,7 @@ typedef struct QError {
|
||||||
QError *qerror_new(void);
|
QError *qerror_new(void);
|
||||||
QError *qerror_from_info(const char *file, int linenr, const char *func,
|
QError *qerror_from_info(const char *file, int linenr, const char *func,
|
||||||
const char *fmt, va_list *va);
|
const char *fmt, va_list *va);
|
||||||
|
QString *qerror_human(const QError *qerror);
|
||||||
void qerror_print(const QError *qerror);
|
void qerror_print(const QError *qerror);
|
||||||
QError *qobject_to_qerror(const QObject *obj);
|
QError *qobject_to_qerror(const QObject *obj);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue