From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PATCH RFC] error: Include hint everywhere
Date: Mon, 18 Dec 2017 22:41:45 +0800 [thread overview]
Message-ID: <20171218144145.13579-1-famz@redhat.com> (raw)
Previously we only print hint lines if we are in a command line context
or HMP. However QMP errors are also eventually consumed by human and the
hint could help.
Append hint lines already in error_get_pretty() and do as said above
consistently in CLI, HMP and QMP.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
We could drop Error.hint because now it's is unused outside of
error_append_hint, but I tend to see Error.pretty as a cache and 'hint'
is the authentic data.
---
util/error.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/util/error.c b/util/error.c
index 3efdd69162..f42ae248b4 100644
--- a/util/error.c
+++ b/util/error.c
@@ -24,6 +24,7 @@ struct Error
const char *src, *func;
int line;
GString *hint;
+ GString *pretty;
};
Error *error_abort;
@@ -166,6 +167,11 @@ void error_append_hint(Error **errp, const char *fmt, ...)
g_string_append_vprintf(err->hint, fmt, ap);
va_end(ap);
+ if (!err->pretty) {
+ err->pretty = g_string_new(NULL);
+ }
+ g_string_printf(err->pretty, "%s\n%s", err->msg, err->hint->str);
+
errno = saved_errno;
}
@@ -206,8 +212,10 @@ Error *error_copy(const Error *err)
err_new->src = err->src;
err_new->line = err->line;
err_new->func = err->func;
+ assert(!!err->hint == !!err->pretty);
if (err->hint) {
err_new->hint = g_string_new(err->hint->str);
+ err_new->pretty = g_string_new(err->pretty->str);
}
return err_new;
@@ -220,24 +228,24 @@ ErrorClass error_get_class(const Error *err)
const char *error_get_pretty(const Error *err)
{
- return err->msg;
+ if (err->pretty) {
+ assert(err->hint);
+ return err->pretty->str;
+ } else {
+ assert(!err->hint);
+ return err->msg;
+ }
}
void error_report_err(Error *err)
{
error_report("%s", error_get_pretty(err));
- if (err->hint) {
- error_printf_unless_qmp("%s", err->hint->str);
- }
error_free(err);
}
void warn_report_err(Error *err)
{
warn_report("%s", error_get_pretty(err));
- if (err->hint) {
- error_printf_unless_qmp("%s", err->hint->str);
- }
error_free(err);
}
@@ -268,6 +276,7 @@ void error_free(Error *err)
g_free(err->msg);
if (err->hint) {
g_string_free(err->hint, true);
+ g_string_free(err->pretty, true);
}
g_free(err);
}
--
2.14.3
next reply other threads:[~2017-12-18 14:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-18 14:41 Fam Zheng [this message]
2017-12-19 14:29 ` [Qemu-devel] [PATCH RFC] error: Include hint everywhere Markus Armbruster
2017-12-20 6:30 ` Fam Zheng
2017-12-20 9:05 ` Markus Armbruster
2017-12-20 9:30 ` Fam Zheng
2017-12-20 14:44 ` Markus Armbruster
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=20171218144145.13579-1-famz@redhat.com \
--to=famz@redhat.com \
--cc=armbru@redhat.com \
--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).