json-parser: propagate error from parser
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
d5ec4f27c3
commit
ef749d07e7
4
Makefile
4
Makefile
@ -134,14 +134,14 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
|
|||||||
|
|
||||||
check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o check-qjson.o: $(GENERATED_HEADERS)
|
check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o check-qjson.o: $(GENERATED_HEADERS)
|
||||||
|
|
||||||
CHECK_PROG_DEPS = qemu-malloc.o $(oslib-obj-y) $(trace-obj-y)
|
CHECK_PROG_DEPS = qemu-malloc.o $(oslib-obj-y) $(trace-obj-y) qemu-tool.o
|
||||||
|
|
||||||
check-qint: check-qint.o qint.o $(CHECK_PROG_DEPS)
|
check-qint: check-qint.o qint.o $(CHECK_PROG_DEPS)
|
||||||
check-qstring: check-qstring.o qstring.o $(CHECK_PROG_DEPS)
|
check-qstring: check-qstring.o qstring.o $(CHECK_PROG_DEPS)
|
||||||
check-qdict: check-qdict.o qdict.o qfloat.o qint.o qstring.o qbool.o qlist.o $(CHECK_PROG_DEPS)
|
check-qdict: check-qdict.o qdict.o qfloat.o qint.o qstring.o qbool.o qlist.o $(CHECK_PROG_DEPS)
|
||||||
check-qlist: check-qlist.o qlist.o qint.o $(CHECK_PROG_DEPS)
|
check-qlist: check-qlist.o qlist.o qint.o $(CHECK_PROG_DEPS)
|
||||||
check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS)
|
check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS)
|
||||||
check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o $(CHECK_PROG_DEPS)
|
check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o error.o qerror.o qemu-error.o $(CHECK_PROG_DEPS)
|
||||||
|
|
||||||
QEMULIBS=libhw32 libhw64 libuser libdis libdis-user
|
QEMULIBS=libhw32 libhw64 libuser libdis libdis-user
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# QObject
|
# QObject
|
||||||
qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
|
qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
|
||||||
qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
|
qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
|
||||||
qobject-obj-y += qerror.o
|
qobject-obj-y += qerror.o error.o
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
# oslib-obj-y is code depending on the OS (win32 vs posix)
|
# oslib-obj-y is code depending on the OS (win32 vs posix)
|
||||||
@ -59,7 +59,7 @@ fsdev-obj-$(CONFIG_VIRTFS) += $(addprefix fsdev/, $(fsdev-nested-y))
|
|||||||
# system emulation, i.e. a single QEMU executable should support all
|
# system emulation, i.e. a single QEMU executable should support all
|
||||||
# CPUs and machines.
|
# CPUs and machines.
|
||||||
|
|
||||||
common-obj-y = $(block-obj-y) blockdev.o error.o
|
common-obj-y = $(block-obj-y) blockdev.o
|
||||||
common-obj-y += $(net-obj-y)
|
common-obj-y += $(net-obj-y)
|
||||||
common-obj-y += $(qobject-obj-y)
|
common-obj-y += $(qobject-obj-y)
|
||||||
common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
|
common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
|
||||||
|
@ -22,9 +22,11 @@
|
|||||||
#include "qbool.h"
|
#include "qbool.h"
|
||||||
#include "json-parser.h"
|
#include "json-parser.h"
|
||||||
#include "json-lexer.h"
|
#include "json-lexer.h"
|
||||||
|
#include "qerror.h"
|
||||||
|
|
||||||
typedef struct JSONParserContext
|
typedef struct JSONParserContext
|
||||||
{
|
{
|
||||||
|
Error *err;
|
||||||
} JSONParserContext;
|
} JSONParserContext;
|
||||||
|
|
||||||
#define BUG_ON(cond) assert(!(cond))
|
#define BUG_ON(cond) assert(!(cond))
|
||||||
@ -95,11 +97,15 @@ static void GCC_FMT_ATTR(3, 4) parse_error(JSONParserContext *ctxt,
|
|||||||
QObject *token, const char *msg, ...)
|
QObject *token, const char *msg, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
char message[1024];
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
fprintf(stderr, "parse error: ");
|
vsnprintf(message, sizeof(message), msg, ap);
|
||||||
vfprintf(stderr, msg, ap);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
if (ctxt->err) {
|
||||||
|
error_free(ctxt->err);
|
||||||
|
ctxt->err = NULL;
|
||||||
|
}
|
||||||
|
error_set(&ctxt->err, QERR_JSON_PARSE_ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -564,6 +570,11 @@ static QObject *parse_value(JSONParserContext *ctxt, QList **tokens, va_list *ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
QObject *json_parser_parse(QList *tokens, va_list *ap)
|
QObject *json_parser_parse(QList *tokens, va_list *ap)
|
||||||
|
{
|
||||||
|
return json_parser_parse_err(tokens, ap, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *json_parser_parse_err(QList *tokens, va_list *ap, Error **errp)
|
||||||
{
|
{
|
||||||
JSONParserContext ctxt = {};
|
JSONParserContext ctxt = {};
|
||||||
QList *working = qlist_copy(tokens);
|
QList *working = qlist_copy(tokens);
|
||||||
@ -573,5 +584,7 @@ QObject *json_parser_parse(QList *tokens, va_list *ap)
|
|||||||
|
|
||||||
QDECREF(working);
|
QDECREF(working);
|
||||||
|
|
||||||
|
error_propagate(errp, ctxt.err);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
#include "qlist.h"
|
#include "qlist.h"
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
QObject *json_parser_parse(QList *tokens, va_list *ap);
|
QObject *json_parser_parse(QList *tokens, va_list *ap);
|
||||||
|
QObject *json_parser_parse_err(QList *tokens, va_list *ap, Error **errp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
3
qerror.h
3
qerror.h
@ -121,6 +121,9 @@ QError *qobject_to_qerror(const QObject *obj);
|
|||||||
#define QERR_JSON_PARSING \
|
#define QERR_JSON_PARSING \
|
||||||
"{ 'class': 'JSONParsing', 'data': {} }"
|
"{ 'class': 'JSONParsing', 'data': {} }"
|
||||||
|
|
||||||
|
#define QERR_JSON_PARSE_ERROR \
|
||||||
|
"{ 'class': 'JSONParseError', 'data': { 'message': %s } }"
|
||||||
|
|
||||||
#define QERR_KVM_MISSING_CAP \
|
#define QERR_KVM_MISSING_CAP \
|
||||||
"{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }"
|
"{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user