From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, armbru@redhat.com,
afaerber@suse.de, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort()
Date: Wed, 25 Jul 2012 17:50:20 -0300 [thread overview]
Message-ID: <1343249431-9245-4-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1343249431-9245-1-git-send-email-lcapitulino@redhat.com>
Previously, developers had to create error dicts manually and also enter
the matching desc table entry. Thus, qerro_abort() was added to help
catching bad error dicts.
Today, all that stuff is generated automatically which makes the chance
of a bad generated dict quite low.
Also, qerror_abort() would... _abort_ on a bad error dict!
This commit maintains the same verification logic on the error object
but drops the abort() in favor of reporting UndefinedError for bad dicts
(and also print a debug message to stderr).
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
qerror.c | 83 +++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 46 insertions(+), 37 deletions(-)
diff --git a/qerror.c b/qerror.c
index d428b52..74b3659 100644
--- a/qerror.c
+++ b/qerror.c
@@ -38,55 +38,50 @@ static QError *qerror_new(void)
return qerr;
}
-static void GCC_FMT_ATTR(2, 3) qerror_abort(const QError *qerr,
- const char *fmt, ...)
-{
- va_list ap;
-
- fprintf(stderr, "qerror: bad call in function '%s':\n", qerr->func);
- fprintf(stderr, "qerror: -> ");
-
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
- va_end(ap);
-
- fprintf(stderr, "\nqerror: call at %s:%d\n", qerr->file, qerr->linenr);
- abort();
-}
-
-static void GCC_FMT_ATTR(2, 0) qerror_set_data(QError *qerr,
- const char *fmt, va_list *va)
+static QDict *error_object_from_fmt(const char *fmt, va_list *va)
{
QObject *obj;
+ QDict *ret;
obj = qobject_from_jsonv(fmt, va);
if (!obj) {
- qerror_abort(qerr, "invalid format '%s'", fmt);
+ fprintf(stderr, "invalid json in error dict '%s'\n", fmt);
+ return NULL;
}
if (qobject_type(obj) != QTYPE_QDICT) {
- qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
+ fprintf(stderr, "error is not a dict '%s'\n", fmt);
+ goto out_free;
}
- qerr->error = qobject_to_qdict(obj);
-
- obj = qdict_get(qerr->error, "class");
+ ret = qobject_to_qdict(obj);
+ obj = qdict_get(ret, "class");
if (!obj) {
- qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
+ fprintf(stderr, "missing 'class' key in '%s'\n", fmt);
+ goto out_free;
}
if (qobject_type(obj) != QTYPE_QSTRING) {
- qerror_abort(qerr, "'class' key value should be a QString");
+ fprintf(stderr, "'class' key value should be a string in '%s'\n", fmt);
+ goto out_free;
}
-
- obj = qdict_get(qerr->error, "data");
+
+ obj = qdict_get(ret, "data");
if (!obj) {
- qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
+ fprintf(stderr, "missing 'data' key in '%s'\n", fmt);
+ goto out_free;
}
if (qobject_type(obj) != QTYPE_QDICT) {
- qerror_abort(qerr, "'data' key value should be a QDICT");
+ fprintf(stderr, "'data' key value should be a dict in '%s'\n", fmt);
+ goto out_free;
}
+
+ return ret;
+
+out_free:
+ qobject_decref(obj);
+ return NULL;
}
-static void qerror_set_desc(QError *qerr, const char *fmt)
+static const QErrorStringTable *error_get_desc(const char *fmt)
{
int i;
@@ -94,12 +89,17 @@ static void qerror_set_desc(QError *qerr, const char *fmt)
for (i = 0; qerror_table[i].error_fmt; i++) {
if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
- qerr->entry = &qerror_table[i];
- return;
+ return &qerror_table[i];
}
}
- qerror_abort(qerr, "error format '%s' not found", fmt);
+ fprintf(stderr, "error format '%s' not found\n", fmt);
+ return NULL;
+}
+
+static QDict *build_error_no_arg(const char *fmt)
+{
+ return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
}
/**
@@ -127,13 +127,22 @@ static QError *qerror_from_info(const char *file, int linenr, const char *func,
qerr->file = file;
qerr->func = func;
- if (!fmt) {
- qerror_abort(qerr, "QDict not specified");
+ qerr->error = error_object_from_fmt(fmt, va);
+ if (!qerr->error) {
+ goto bad_err;
+ }
+
+ qerr->entry = error_get_desc(fmt);
+ if (!qerr->entry) {
+ QDECREF(qerr->error);
+ goto bad_err;
}
- qerror_set_data(qerr, fmt, va);
- qerror_set_desc(qerr, fmt);
+ return qerr;
+bad_err:
+ qerr->error = build_error_no_arg(QERR_UNDEFINED_ERROR);
+ qerr->entry = error_get_desc(QERR_UNDEFINED_ERROR);
return qerr;
}
--
1.7.11.2.249.g31c7954.dirty
next prev parent reply other threads:[~2012-07-25 20:50 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure Luiz Capitulino
2012-07-25 20:50 ` Luiz Capitulino [this message]
2012-07-26 12:33 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Markus Armbruster
2012-07-26 15:02 ` Luiz Capitulino
2012-07-26 12:59 ` Eric Blake
2012-07-25 20:50 ` [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal() Luiz Capitulino
2012-07-26 12:35 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 07/14] error: " Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[] Luiz Capitulino
2012-07-26 12:52 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 10/14] error: error_set(): " Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good Luiz Capitulino
2012-07-26 12:54 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 14/14] error: change all error_set() " Luiz Capitulino
2012-07-26 2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
2012-07-26 9:45 ` Kevin Wolf
2012-07-26 12:41 ` Anthony Liguori
2012-07-26 14:12 ` Luiz Capitulino
2012-07-26 15:05 ` Anthony Liguori
2012-07-26 15:52 ` Markus Armbruster
2012-07-26 14:40 ` Kevin Wolf
2012-07-26 15:20 ` Anthony Liguori
2012-07-26 16:12 ` Daniel P. Berrange
2012-07-26 16:38 ` Markus Armbruster
2012-07-26 15:54 ` Markus Armbruster
2012-07-26 16:03 ` Paolo Bonzini
2012-07-26 16:37 ` Luiz Capitulino
2012-07-27 13:17 ` Andreas Färber
2012-07-27 13:45 ` Anthony Liguori
2012-07-27 14:27 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343249431-9245-4-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).