Make error reporting for QEMU JSON mode more friendly
Current error reporting for JSON mode returns the full JSON command string and full JSON error string. This is not very user friendly, so this change makes the error report only contain the basic command name, and friendly error message description string. The full JSON data is logged instead. * src/qemu/qemu_monitor_json.c: Always return the 'desc' field from the JSON error message to users.
This commit is contained in:
parent
5d72a89442
commit
b6b8009548
@ -246,15 +246,33 @@ qemuMonitorJSONCommand(qemuMonitorPtr mon,
|
|||||||
*
|
*
|
||||||
* XXX see qerror.h for different klasses & fill out useful params
|
* XXX see qerror.h for different klasses & fill out useful params
|
||||||
*/
|
*/
|
||||||
static char *qemuMonitorJSONStringifyError(virJSONValuePtr error)
|
static const char *
|
||||||
|
qemuMonitorJSONStringifyError(virJSONValuePtr error)
|
||||||
{
|
{
|
||||||
const char *klass = virJSONValueObjectGetString(error, "class");
|
const char *klass = virJSONValueObjectGetString(error, "class");
|
||||||
|
const char *detail = NULL;
|
||||||
|
|
||||||
if (klass) {
|
/* The QMP 'desc' field is usually sufficient for our generic
|
||||||
return strdup(klass);
|
* error reporting needs.
|
||||||
} else {
|
*/
|
||||||
return strdup(_("Missing QEMU error klass"));
|
if (klass)
|
||||||
}
|
detail = virJSONValueObjectGetString(error, "desc");
|
||||||
|
|
||||||
|
|
||||||
|
if (!detail)
|
||||||
|
detail = "unknown QEMU command error";
|
||||||
|
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
qemuMonitorJSONCommandName(virJSONValuePtr cmd)
|
||||||
|
{
|
||||||
|
const char *name = virJSONValueObjectGetString(cmd, "execute");
|
||||||
|
if (name)
|
||||||
|
return name;
|
||||||
|
else
|
||||||
|
return "<unknown>";
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -266,20 +284,21 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
|
|||||||
char *cmdstr = virJSONValueToString(cmd);
|
char *cmdstr = virJSONValueToString(cmd);
|
||||||
char *replystr = virJSONValueToString(reply);
|
char *replystr = virJSONValueToString(reply);
|
||||||
|
|
||||||
if (!error) {
|
/* Log the full JSON formatted command & error */
|
||||||
VIR_DEBUG("Saw a JSON error, but value is null for %s: %s",
|
VIR_DEBUG("unable to execute QEMU command %s: %s",
|
||||||
cmdstr, replystr);
|
cmdstr, replystr);
|
||||||
|
|
||||||
|
/* Only send the user the command name + friendly error */
|
||||||
|
if (!error)
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("error running QEMU command '%s': '%s'"),
|
_("unable to execute QEMU command '%s'"),
|
||||||
cmdstr, replystr);
|
qemuMonitorJSONCommandName(cmd));
|
||||||
} else {
|
else
|
||||||
VIR_DEBUG("Got a JSON error set for %s", cmdstr);
|
|
||||||
char *detail = qemuMonitorJSONStringifyError(error);
|
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("error running QEMU command '%s': %s ('%s')"),
|
_("unable to execute QEMU command '%s': %s"),
|
||||||
cmdstr, detail, replystr);
|
qemuMonitorJSONCommandName(cmd),
|
||||||
VIR_FREE(detail);
|
qemuMonitorJSONStringifyError(error));
|
||||||
}
|
|
||||||
VIR_FREE(cmdstr);
|
VIR_FREE(cmdstr);
|
||||||
VIR_FREE(replystr);
|
VIR_FREE(replystr);
|
||||||
return -1;
|
return -1;
|
||||||
@ -290,7 +309,8 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
|
|||||||
VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
|
VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
|
||||||
cmdstr, replystr);
|
cmdstr, replystr);
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("error running QEMU command '%s': '%s'"), cmdstr, replystr);
|
_("unable to execute QEMU command '%s'"),
|
||||||
|
qemuMonitorJSONCommandName(cmd));
|
||||||
VIR_FREE(cmdstr);
|
VIR_FREE(cmdstr);
|
||||||
VIR_FREE(replystr);
|
VIR_FREE(replystr);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user