From 4c5a1e4db7c68b0e7edf5687dc10beeb776bad9f Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Mon, 7 Mar 2011 17:05:04 +0800 Subject: QMP: QError: New QERR_UNSUPPORTED New QERR_UNSUPPORTED for unsupported commands or requests. Signed-off-by: Luiz Capitulino --- qerror.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'qerror.c') diff --git a/qerror.c b/qerror.c index 4855604..4f3b7ca 100644 --- a/qerror.c +++ b/qerror.c @@ -201,6 +201,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "An undefined error has ocurred", }, { + .error_fmt = QERR_UNSUPPORTED, + .desc = "this feature or command is not currently supported", + }, + { .error_fmt = QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, .desc = "'%(device)' uses a %(format) feature which is not " "supported by this qemu version: %(feature)", -- cgit v1.1 From a12eeaaa4fdaed9ed4a92f337b5f3c8a5a3fb946 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Wed, 1 Jun 2011 12:14:47 -0500 Subject: QError: Introduce qerror_format_desc() Refactor non-QError-specific bits out of qerror_human() into general function that can be used by the error_get_pretty() analogue in the new error-propagation framework. Signed-off-by: Luiz Capitulino Signed-off-by: Michael Roth Signed-off-by: Anthony Liguori --- qerror.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'qerror.c') diff --git a/qerror.c b/qerror.c index 4855604..af6ed39 100644 --- a/qerror.c +++ b/qerror.c @@ -326,12 +326,14 @@ QError *qerror_from_info(const char *file, int linenr, const char *func, return qerr; } -static void parse_error(const QError *qerror, int c) +static void parse_error(const QErrorStringTable *entry, int c) { - qerror_abort(qerror, "expected '%c' in '%s'", c, qerror->entry->desc); + fprintf(stderr, "expected '%c' in '%s'", c, entry->desc); + abort(); } -static const char *append_field(QString *outstr, const QError *qerror, +static const char *append_field(QDict *error, QString *outstr, + const QErrorStringTable *entry, const char *start) { QObject *obj; @@ -340,23 +342,23 @@ static const char *append_field(QString *outstr, const QError *qerror, const char *end, *key; if (*start != '%') - parse_error(qerror, '%'); + parse_error(entry, '%'); start++; if (*start != '(') - parse_error(qerror, '('); + parse_error(entry, '('); start++; end = strchr(start, ')'); if (!end) - parse_error(qerror, ')'); + parse_error(entry, ')'); key_qs = qstring_from_substr(start, 0, end - start - 1); key = qstring_get_str(key_qs); - qdict = qobject_to_qdict(qdict_get(qerror->error, "data")); + qdict = qobject_to_qdict(qdict_get(error, "data")); obj = qdict_get(qdict, key); if (!obj) { - qerror_abort(qerror, "key '%s' not found in QDict", key); + abort(); } switch (qobject_type(obj)) { @@ -367,35 +369,31 @@ static const char *append_field(QString *outstr, const QError *qerror, qstring_append_int(outstr, qdict_get_int(qdict, key)); break; default: - qerror_abort(qerror, "invalid type '%c'", qobject_type(obj)); + abort(); } QDECREF(key_qs); return ++end; } -/** - * qerror_human(): Format QError data into human-readable string. - * - * Formats according to member 'desc' of the specified QError object. - */ -QString *qerror_human(const QError *qerror) +static QString *qerror_format_desc(QDict *error, + const QErrorStringTable *entry) { - const char *p; QString *qstring; + const char *p; - assert(qerror->entry != NULL); + assert(entry != NULL); qstring = qstring_new(); - for (p = qerror->entry->desc; *p != '\0';) { + for (p = entry->desc; *p != '\0';) { if (*p != '%') { qstring_append_chr(qstring, *p++); } else if (*(p + 1) == '%') { qstring_append_chr(qstring, '%'); p += 2; } else { - p = append_field(qstring, qerror, p); + p = append_field(error, qstring, entry, p); } } @@ -403,6 +401,14 @@ QString *qerror_human(const QError *qerror) } /** + * qerror_human(): Format QError data into human-readable string. + */ +QString *qerror_human(const QError *qerror) +{ + return qerror_format_desc(qerror->error, qerror->entry); +} + +/** * qerror_print(): Print QError data * * This function will print the member 'desc' of the specified QError object, -- cgit v1.1 From 87c2f59166b7ec5b3ce44b5c4a2337c07a78e533 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Wed, 1 Jun 2011 12:14:48 -0500 Subject: QError: Introduce qerror_format() Will be used by new error propagation framework to convert Error objects into human-readable form. Signed-off-by: Luiz Capitulino Signed-off-by: Michael Roth Signed-off-by: Anthony Liguori --- qerror.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'qerror.c') diff --git a/qerror.c b/qerror.c index af6ed39..c18641f 100644 --- a/qerror.c +++ b/qerror.c @@ -400,6 +400,21 @@ static QString *qerror_format_desc(QDict *error, return qstring; } +QString *qerror_format(const char *fmt, QDict *error) +{ + const QErrorStringTable *entry = NULL; + int i; + + for (i = 0; qerror_table[i].error_fmt; i++) { + if (strcmp(qerror_table[i].error_fmt, fmt) == 0) { + entry = &qerror_table[i]; + break; + } + } + + return qerror_format_desc(error, entry); +} + /** * qerror_human(): Format QError data into human-readable string. */ -- cgit v1.1