diff options
author | Markus Armbruster <armbru@redhat.com> | 2018-07-03 10:53:48 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-07-03 23:18:56 +0200 |
commit | cee32796cadc9510ee00f029a933009df7a28ae2 (patch) | |
tree | 1fb09ff3405d4ca4b75afc6304047f7376dd1ece /qga/main.c | |
parent | a193352ff9c7cd2cd07846118bc49921d0f53af8 (diff) |
qmp: De-duplicate error response building
All callers of qmp_build_error_object() duplicate the code to wrap it
in a response object. Replace it by qmp_error_response() that
captures the duplicated code, including error_free().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-23-armbru@redhat.com>
Diffstat (limited to 'qga/main.c')
-rw-r--r-- | qga/main.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/qga/main.c b/qga/main.c index d332bacce5..0e30e30248 100644 --- a/qga/main.c +++ b/qga/main.c @@ -610,15 +610,13 @@ static void process_event(JSONMessageParser *parser, GQueue *tokens) qdict = qobject_to(QDict, json_parser_parse_err(tokens, NULL, &err)); if (err || !qdict) { qobject_unref(qdict); - qdict = qdict_new(); if (!err) { g_warning("failed to parse event: unknown error"); error_setg(&err, QERR_JSON_PARSING); } else { g_warning("failed to parse event: %s", error_get_pretty(err)); } - qdict_put_obj(qdict, "error", qmp_build_error_object(err)); - error_free(err); + qdict = qmp_error_response(err); } /* handle host->guest commands */ @@ -627,11 +625,9 @@ static void process_event(JSONMessageParser *parser, GQueue *tokens) } else { if (!qdict_haskey(qdict, "error")) { qobject_unref(qdict); - qdict = qdict_new(); g_warning("unrecognized payload format"); error_setg(&err, QERR_UNSUPPORTED); - qdict_put_obj(qdict, "error", qmp_build_error_object(err)); - error_free(err); + qdict = qmp_error_response(err); } ret = send_response(s, QOBJECT(qdict)); if (ret < 0) { |