qemu/qobject
Markus Armbruster 84a56f38b2 json: Pass lexical errors and limit violations to callback
The callback to consume JSON values takes QObject *json, Error *err.
If both are null, the callback is supposed to make up an error by
itself.  This sucks.

qjson.c's consume_json() neglects to do so, which makes
qobject_from_json() null instead of failing.  I consider that a bug.

The culprit is json_message_process_token(): it passes two null
pointers when it runs into a lexical error or a limit violation.  Fix
it to pass a proper Error object then.  Update the callbacks:

* monitor.c's handle_qmp_command(): the code to make up an error is
  now dead, drop it.

* qga/main.c's process_event(): lumps the "both null" case together
  with the "not a JSON object" case.  The former is now gone.  The
  error message "Invalid JSON syntax" is misleading for the latter.
  Improve it to "Input must be a JSON object".

* qobject/qjson.c's consume_json(): no update; check-qjson
  demonstrates qobject_from_json() now sets an error on lexical
  errors, but still doesn't on some other errors.

* tests/libqtest.c's qmp_response(): the Error object is now reliable,
  so use it to improve the error message.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180823164025.12553-40-armbru@redhat.com>
2018-08-24 20:26:37 +02:00
..
block-qdict.c qdict: Make qdict_extract_subqdict() accept dst = NULL 2018-08-15 12:50:39 +02:00
json-lexer.c json: Pass lexical errors and limit violations to callback 2018-08-24 20:26:37 +02:00
json-parser.c json: Treat unwanted interpolation as lexical error 2018-08-24 20:26:37 +02:00
json-streamer.c json: Pass lexical errors and limit violations to callback 2018-08-24 20:26:37 +02:00
Makefile.objs qobject: Move block-specific qdict code to block-qdict.c 2018-06-15 14:49:44 +02:00
qbool.c qapi: Remove qobject_to_X() functions 2018-03-19 14:58:36 -05:00
qdict.c qobject: Move block-specific qdict code to block-qdict.c 2018-06-15 14:49:44 +02:00
qjson.c json: Redesign the callback to consume JSON values 2018-08-24 20:26:37 +02:00
qlist.c qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF 2018-05-04 08:27:53 +02:00
qlit.c qapi: Replace qobject_to_X(o) by qobject_to(X, o) 2018-03-19 14:58:36 -05:00
qnull.c qapi: Add qobject_is_equal() 2017-11-17 18:21:30 +01:00
qnum.c qapi: Remove qobject_to_X() functions 2018-03-19 14:58:36 -05:00
qobject.c qobject: use a QObjectBase_ struct 2018-05-04 08:27:53 +02:00
qstring.c qstring: Move qstring_from_substr()'s @end one to the right 2018-07-28 09:09:58 +02:00