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>
struct Error
{
QDict *obj;
- const char *fmt;
char *msg;
};
va_start(ap, fmt);
err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap));
va_end(ap);
- err->fmt = fmt;
+ err->msg = qerror_format(fmt, err->obj);
*errp = err;
}
err_new = g_malloc0(sizeof(*err));
err_new->msg = g_strdup(err->msg);
- err_new->fmt = err->fmt;
err_new->obj = err->obj;
QINCREF(err_new->obj);
const char *error_get_pretty(Error *err)
{
- if (err->msg == NULL) {
- err->msg = qerror_format(err->fmt, err->obj);
- }
-
return err->msg;
}
struct Error
{
QDict *obj;
- const char *fmt;
char *msg;
};
loc_save(&qerr->loc);
QINCREF(err->obj);
qerr->error = err->obj;
-
- qerr->err_msg = qerror_format(err->fmt, qerr->error);
+ qerr->err_msg = g_strdup(err->msg);
if (monitor_cur_is_qmp()) {
monitor_set_error(cur_mon, qerr);