[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 07/11] json: propagate error from parser
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 07/11] json: propagate error from parser |
Date: |
Fri, 11 Mar 2011 15:00:45 -0600 |
Signed-off-by: Anthony Liguori <address@hidden>
diff --git a/json-parser.c b/json-parser.c
index 6c06ef9..ac4063a 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;
}
diff --git a/json-parser.h b/json-parser.h
index 97f43f6..8f2b5ec 100644
--- a/json-parser.h
+++ b/json-parser.h
@@ -16,7 +16,9 @@
#include "qemu-common.h"
#include "qlist.h"
+#include "error.h"
QObject *json_parser_parse(QList *tokens, va_list *ap);
+QObject *json_parser_parse_err(QList *tokens, va_list *ap, Error **errp);
#endif
--
1.7.0.4
- [Qemu-devel] [00/11] QAPI Round 0 (JSON improvements), Anthony Liguori, 2011/03/11
- [Qemu-devel] [PATCH 07/11] json: propagate error from parser,
Anthony Liguori <=
- [Qemu-devel] [PATCH 11/11] json-parser: detect premature EOI, Anthony Liguori, 2011/03/11
- [Qemu-devel] [PATCH 05/11] qerror: add new error message for invalid enum values, Anthony Liguori, 2011/03/11
- [Qemu-devel] [PATCH 02/11] qerror: expose a function to format an error, Anthony Liguori, 2011/03/11
- [Qemu-devel] Re: [PATCH 02/11] qerror: expose a function to format an error, Anthony Liguori, 2011/03/11
- [Qemu-devel] Re: [PATCH 02/11] qerror: expose a function to format an error, Luiz Capitulino, 2011/03/14
- Re: [Qemu-devel] Re: [PATCH 02/11] qerror: expose a function to format an error, Anthony Liguori, 2011/03/14
- Re: [Qemu-devel] Re: [PATCH 02/11] qerror: expose a function to format an error, Luiz Capitulino, 2011/03/14
- Re: [Qemu-devel] Re: [PATCH 02/11] qerror: expose a function to format an error, Anthony Liguori, 2011/03/14
- Re: [Qemu-devel] Re: [PATCH 02/11] qerror: expose a function to format an error, Luiz Capitulino, 2011/03/14