aboutsummaryrefslogtreecommitdiff
path: root/util/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/error.c')
-rw-r--r--util/error.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/util/error.c b/util/error.c
index 80c89a2079..57303fd05c 100644
--- a/util/error.c
+++ b/util/error.c
@@ -122,6 +122,29 @@ void error_setg_file_open_internal(Error **errp,
"Could not open '%s'", filename);
}
+void error_vprepend(Error **errp, const char *fmt, va_list ap)
+{
+ GString *newmsg;
+
+ if (!errp) {
+ return;
+ }
+
+ newmsg = g_string_new(NULL);
+ g_string_vprintf(newmsg, fmt, ap);
+ g_string_append(newmsg, (*errp)->msg);
+ (*errp)->msg = g_string_free(newmsg, 0);
+}
+
+void error_prepend(Error **errp, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ error_vprepend(errp, fmt, ap);
+ va_end(ap);
+}
+
void error_append_hint(Error **errp, const char *fmt, ...)
{
va_list ap;
@@ -132,7 +155,7 @@ void error_append_hint(Error **errp, const char *fmt, ...)
return;
}
err = *errp;
- assert(err && errp != &error_abort);
+ assert(err && errp != &error_abort && errp != &error_fatal);
if (!err->hint) {
err->hint = g_string_new(NULL);
@@ -204,11 +227,21 @@ void error_report_err(Error *err)
{
error_report("%s", error_get_pretty(err));
if (err->hint) {
- error_printf_unless_qmp("%s\n", err->hint->str);
+ error_printf_unless_qmp("%s", err->hint->str);
}
error_free(err);
}
+void error_reportf_err(Error *err, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ error_vprepend(&err, fmt, ap);
+ va_end(ap);
+ error_report_err(err);
+}
+
void error_free(Error *err)
{
if (err) {