From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzhUX-0001ll-0z for qemu-devel@nongnu.org; Tue, 02 Jun 2015 04:24:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzhUU-0000iW-At for qemu-devel@nongnu.org; Tue, 02 Jun 2015 04:24:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzhUU-0000hy-2x for qemu-devel@nongnu.org; Tue, 02 Jun 2015 04:24:06 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id C1028A10A2 for ; Tue, 2 Jun 2015 08:24:05 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t528O3eN029749 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 2 Jun 2015 04:24:04 -0400 From: Markus Armbruster Date: Tue, 2 Jun 2015 10:23:52 +0200 Message-Id: <1433233439-3386-15-git-send-email-armbru@redhat.com> In-Reply-To: <1433233439-3386-1-git-send-email-armbru@redhat.com> References: <1433233439-3386-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PULL 14/21] monitor: Limit QError use to command handlers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org The previous commits narrowed use of QError to handle_qmp_command() and its helpers monitor_protocol_emitter(), build_qmp_error_dict(). Narrow it further to just the command handler call: instead of converting Error to QError throughout handle_qmp_command(), convert the QError gotten from the command handler to Error, and switch the helpers from QError to Error. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Luiz Capitulino --- monitor.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/monitor.c b/monitor.c index 91f8a4e..888d771 100644 --- a/monitor.c +++ b/monitor.c @@ -391,19 +391,19 @@ static void monitor_json_emitter(Monitor *mon, const QObject *data) QDECREF(json); } -static QDict *build_qmp_error_dict(const QError *err) +static QDict *build_qmp_error_dict(Error *err) { QObject *obj; - obj = qobject_from_jsonf("{ 'error': { 'class': %s, 'desc': %p } }", - ErrorClass_lookup[err->err_class], - qerror_human(err)); + obj = qobject_from_jsonf("{ 'error': { 'class': %s, 'desc': %s } }", + ErrorClass_lookup[error_get_class(err)], + error_get_pretty(err)); return qobject_to_qdict(obj); } static void monitor_protocol_emitter(Monitor *mon, QObject *data, - QError *err) + Error *err) { QDict *qmp; @@ -4983,13 +4983,12 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) obj = json_parser_parse(tokens, NULL); if (!obj) { // FIXME: should be triggered in json_parser_parse() - qerror_report(QERR_JSON_PARSING); + error_set(&local_err, QERR_JSON_PARSING); goto err_out; } input = qmp_check_input_obj(obj, &local_err); if (!input) { - qerror_report_err(local_err); qobject_decref(obj); goto err_out; } @@ -5001,12 +5000,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) trace_handle_qmp_command(mon, cmd_name); cmd = qmp_find_cmd(cmd_name); if (!cmd) { - qerror_report(ERROR_CLASS_COMMAND_NOT_FOUND, - "The command %s has not been found", cmd_name); + error_set(&local_err, ERROR_CLASS_COMMAND_NOT_FOUND, + "The command %s has not been found", cmd_name); goto err_out; } if (invalid_qmp_mode(mon, cmd, &local_err)) { - qerror_report_err(local_err); goto err_out; } @@ -5020,7 +5018,6 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) qmp_check_client_args(cmd, args, &local_err); if (local_err) { - qerror_report_err(local_err); goto err_out; } @@ -5028,12 +5025,16 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) /* Command failed... */ if (!mon->error) { /* ... without setting an error, so make one up */ - qerror_report(QERR_UNDEFINED_ERROR); + error_set(&local_err, QERR_UNDEFINED_ERROR); } } + if (mon->error) { + error_set(&local_err, mon->error->err_class, "%s", + mon->error->err_msg); + } err_out: - monitor_protocol_emitter(mon, data, mon->error); + monitor_protocol_emitter(mon, data, local_err); qobject_decref(data); QDECREF(mon->error); mon->error = NULL; -- 1.9.3