Let's make json_parser_parse_err() suck less, and simplify caller
error handling.

Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com>
---
 monitor.c             | 4 ----
 qobject/json-parser.c | 7 ++++++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/monitor.c b/monitor.c
index 5889a32231..e9d0c4d172 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4053,10 +4053,6 @@ static void handle_qmp_command(JSONMessageParser 
*parser, GQueue *tokens)
     QMPRequest *req_obj;
 
     req = json_parser_parse_err(tokens, NULL, &err);
-    if (!req && !err) {
-        /* json_parser_parse_err() sucks: can fail without setting @err */
-        error_setg(&err, QERR_JSON_PARSING);
-    }
     if (err) {
         goto err;
     }
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index 769b960c9f..c39cd8e4d7 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -591,7 +591,12 @@ QObject *json_parser_parse_err(GQueue *tokens, va_list 
*ap, Error **errp)
 
     result = parse_value(ctxt, ap);
 
-    error_propagate(errp, ctxt->err);
+    if (!result && !ctxt->err) {
+        /* TODO: improve error reporting */
+        error_setg(errp, "Failed to parse JSON");
+    } else {
+        error_propagate(errp, ctxt->err);
+    }
 
     parser_context_free(ctxt);
 
-- 
2.17.0.rc1.1.g4c4f2b46a3


Reply via email to