error: don't delay error message construction

Today, the error message is only constructed when it's used. This commit
changes that to construct the error message when the error object is
built (ie. when the error is reported).

This simplifies the Error object.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Luiz Capitulino 2012-07-20 13:43:37 -03:00
parent 18da7c0f1f
commit dd7520f064
2 changed files with 2 additions and 10 deletions

View File

@ -20,7 +20,6 @@
struct Error struct Error
{ {
QDict *obj; QDict *obj;
const char *fmt;
char *msg; char *msg;
}; };
@ -39,7 +38,7 @@ void error_set(Error **errp, const char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap)); err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap));
va_end(ap); va_end(ap);
err->fmt = fmt; err->msg = qerror_format(fmt, err->obj);
*errp = err; *errp = err;
} }
@ -50,7 +49,6 @@ Error *error_copy(const Error *err)
err_new = g_malloc0(sizeof(*err)); err_new = g_malloc0(sizeof(*err));
err_new->msg = g_strdup(err->msg); err_new->msg = g_strdup(err->msg);
err_new->fmt = err->fmt;
err_new->obj = err->obj; err_new->obj = err->obj;
QINCREF(err_new->obj); QINCREF(err_new->obj);
@ -64,10 +62,6 @@ bool error_is_set(Error **errp)
const char *error_get_pretty(Error *err) const char *error_get_pretty(Error *err)
{ {
if (err->msg == NULL) {
err->msg = qerror_format(err->fmt, err->obj);
}
return err->msg; return err->msg;
} }

View File

@ -543,7 +543,6 @@ void qerror_report(const char *fmt, ...)
struct Error struct Error
{ {
QDict *obj; QDict *obj;
const char *fmt;
char *msg; char *msg;
}; };
@ -555,8 +554,7 @@ void qerror_report_err(Error *err)
loc_save(&qerr->loc); loc_save(&qerr->loc);
QINCREF(err->obj); QINCREF(err->obj);
qerr->error = err->obj; qerr->error = err->obj;
qerr->err_msg = g_strdup(err->msg);
qerr->err_msg = qerror_format(err->fmt, qerr->error);
if (monitor_cur_is_qmp()) { if (monitor_cur_is_qmp()) {
monitor_set_error(cur_mon, qerr); monitor_set_error(cur_mon, qerr);