diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2011-06-01 12:14:50 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2011-06-07 13:52:10 -0500 |
commit | ef749d07e717ca38b7d8b525c81d6b04db5f16ed (patch) | |
tree | 0b36790a3c9532c6b3c6e7815d9300096518fd2b /json-parser.c | |
parent | d5ec4f27c387c3b3200abb8656343b2519ea3047 (diff) |
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>
Diffstat (limited to 'json-parser.c')
-rw-r--r-- | json-parser.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/json-parser.c b/json-parser.c index 6c06ef91a..ac4063a45 100644 --- a/json-parser.c +++ b/json-parser.c @@ -22,9 +22,11 @@ #include "qbool.h" #include "json-parser.h" #include "json-lexer.h" +#include "qerror.h" typedef struct JSONParserContext { + Error *err; } JSONParserContext; #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, ...) { va_list ap; + char message[1024]; va_start(ap, msg); - fprintf(stderr, "parse error: "); - vfprintf(stderr, msg, ap); - fprintf(stderr, "\n"); + vsnprintf(message, sizeof(message), msg, ap); va_end(ap); + if (ctxt->err) { + error_free(ctxt->err); + ctxt->err = NULL; + } + error_set(&ctxt->err, QERR_JSON_PARSE_ERROR, message); } /** @@ -565,6 +571,11 @@ static QObject *parse_value(JSONParserContext *ctxt, 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 = {}; QList *working = qlist_copy(tokens); QObject *result; @@ -573,5 +584,7 @@ QObject *json_parser_parse(QList *tokens, va_list *ap) QDECREF(working); + error_propagate(errp, ctxt.err); + return result; } |