All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
@ 2012-07-25 20:50 Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code Luiz Capitulino
                   ` (15 more replies)
  0 siblings, 16 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

Basically, this series changes a call like:

 error_set(errp, QERR_DEVICE_NOT_FOUND, device);

to:

 error_set(errp, QERR_DEVICE_NOT_FOUND,
           "Device 'device=%s' not found", device);

In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:

    "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"

error_set() then uses that string and the 'device' argument to build the
error object, which is a QDict. The human error message is fixed, and exists
in the qerror_table[] array. That array is indexed, and the human error
message is added to the error object.

In the new way, QERR_DEVICE_NOT_FOUND is an enumeration value and the
human error message is passed as an argument. qerror_table[] is gone. The
error object is built by using QERR_DEVICE_NOT_FOUND as an index for a table
containing all those json dict strings (this can, and probably will, be
eliminated, as the QMP code can generate its error object from the Error
object).

An important detail is that, the error object data member is constructed
by parsing the human message string and looking for name=value pairs. If
a required data member (like 'device' above) is not found in the human message,
a default value is used ('unknown' for strings and 0 for integers).

This series unlocks several possible simplification, like moving from:

    struct Error
    {
        QDict *obj;
        const char *fmt;
        char *msg;
    };

to:

    struct Error
    {
        ErrClass err_class;
        char *msg;
    };

But I haven't done it all yet.

Please, check individual patches for more details.

 balloon.c                   |  10 +-
 block.c                     |   4 +-
 block/cow.c                 |   3 +-
 block/qcow.c                |   7 +-
 block/qcow2.c               |   3 +-
 block/qed.c                 |   3 +-
 block/stream.c              |   2 +-
 block/vdi.c                 |   4 +-
 block/vmdk.c                |   4 +-
 block/vpc.c                 |   4 +-
 block/vvfat.c               |   4 +-
 blockdev.c                  |  79 +++++++-------
 configure                   |  10 --
 cpus.c                      |  13 ++-
 dump-stub.c                 |   2 +-
 dump.c                      |  18 ++--
 error.c                     |  45 ++------
 error.h                     |   5 +-
 hmp.c                       |   2 +-
 hw/9pfs/virtio-9p.c         |   3 +-
 hw/ivshmem.c                |   2 +-
 hw/pci-stub.c               |   2 +-
 hw/pci.c                    |   4 +-
 hw/qdev-addr.c              |   6 +-
 hw/qdev-monitor.c           |  26 +++--
 hw/qdev-properties.c        |  49 ++++-----
 hw/qdev.c                   |   6 +-
 hw/usb/bus.c                |   3 +-
 hw/usb/hcd-ehci.c           |   6 +-
 hw/usb/redirect.c           |   5 +-
 json-parser.c               |   2 +-
 migration.c                 |   6 +-
 monitor.c                   | 127 +++++------------------
 net.c                       |  20 ++--
 qapi/qapi-visit-core.c      |  22 ++--
 qapi/qmp-dispatch.c         |  14 ++-
 qapi/qmp-input-visitor.c    |  22 ++--
 qapi/string-input-visitor.c |  12 +--
 qemu-config.c               |   2 +-
 qemu-ga.c                   |   4 +-
 qemu-option.c               |  20 ++--
 qemu-sockets.c              |  22 ++--
 qerror.c                    | 243 ++++++++++++++------------------------------
 qerror.h                    |  22 +---
 qga/commands-posix.c        |  78 +++++++-------
 qga/commands-win32.c        |  53 ++++------
 qmp.c                       |  47 +++++----
 qom/object.c                |  20 ++--
 savevm.c                    |   6 +-
 scripts/qapi-errors.py      |  80 ++++++++-------
 target-i386/cpu.c           |  15 +--
 ui/vnc.c                    |   4 +-
 52 files changed, 450 insertions(+), 725 deletions(-)

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure Luiz Capitulino
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

In the old QMP days, this code was used to find out QMP commands that
might be calling monitor_printf() down its call chain.

This is almost impossible to happen today, because the qapi converted
commands don't even have a monitor object. Besides, it's been more than
a year since I used this last time.

Let's just drop it.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 configure | 10 ----------
 monitor.c | 62 --------------------------------------------------------------
 2 files changed, 72 deletions(-)

diff --git a/configure b/configure
index cef0a71..a5e43fd 100755
--- a/configure
+++ b/configure
@@ -147,7 +147,6 @@ vhost_net="no"
 kvm="no"
 gprof="no"
 debug_tcg="no"
-debug_mon="no"
 debug="no"
 strip_opt="yes"
 tcg_interpreter="no"
@@ -633,14 +632,9 @@ for opt do
   ;;
   --disable-debug-tcg) debug_tcg="no"
   ;;
-  --enable-debug-mon) debug_mon="yes"
-  ;;
-  --disable-debug-mon) debug_mon="no"
-  ;;
   --enable-debug)
       # Enable debugging options that aren't excessively noisy
       debug_tcg="yes"
-      debug_mon="yes"
       debug="yes"
       strip_opt="no"
   ;;
@@ -3007,7 +3001,6 @@ echo "host CPU          $cpu"
 echo "host big endian   $bigendian"
 echo "target list       $target_list"
 echo "tcg debug enabled $debug_tcg"
-echo "Mon debug enabled $debug_mon"
 echo "gprof enabled     $gprof"
 echo "sparse enabled    $sparse"
 echo "strip binaries    $strip_opt"
@@ -3100,9 +3093,6 @@ echo "ARCH=$ARCH" >> $config_host_mak
 if test "$debug_tcg" = "yes" ; then
   echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
 fi
-if test "$debug_mon" = "yes" ; then
-  echo "CONFIG_DEBUG_MONITOR=y" >> $config_host_mak
-fi
 if test "$debug" = "yes" ; then
   echo "CONFIG_DEBUG_EXEC=y" >> $config_host_mak
 fi
diff --git a/monitor.c b/monitor.c
index ec4e467..c22cfca 100644
--- a/monitor.c
+++ b/monitor.c
@@ -180,33 +180,6 @@ struct Monitor {
     QLIST_ENTRY(Monitor) entry;
 };
 
-#ifdef CONFIG_DEBUG_MONITOR
-#define MON_DEBUG(fmt, ...) do {    \
-    fprintf(stderr, "Monitor: ");       \
-    fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
-
-static inline void mon_print_count_inc(Monitor *mon)
-{
-    mon->print_calls_nr++;
-}
-
-static inline void mon_print_count_init(Monitor *mon)
-{
-    mon->print_calls_nr = 0;
-}
-
-static inline int mon_print_count_get(const Monitor *mon)
-{
-    return mon->print_calls_nr;
-}
-
-#else /* !CONFIG_DEBUG_MONITOR */
-#define MON_DEBUG(fmt, ...) do { } while (0)
-static inline void mon_print_count_inc(Monitor *mon) { }
-static inline void mon_print_count_init(Monitor *mon) { }
-static inline int mon_print_count_get(const Monitor *mon) { return 0; }
-#endif /* CONFIG_DEBUG_MONITOR */
-
 /* QMP checker flags */
 #define QMP_ACCEPT_UNKNOWNS 1
 
@@ -299,8 +272,6 @@ void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
     if (!mon)
         return;
 
-    mon_print_count_inc(mon);
-
     if (monitor_ctrl_mode(mon)) {
         return;
     }
@@ -3876,8 +3847,6 @@ void monitor_set_error(Monitor *mon, QError *qerror)
     if (!mon->error) {
         mon->error = qerror;
     } else {
-        MON_DEBUG("Additional error report at %s:%d\n",
-                  qerror->file, qerror->linenr);
         QDECREF(qerror);
     }
 }
@@ -3891,36 +3860,7 @@ static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
          * Action: Report an internal error to the client if in QMP.
          */
         qerror_report(QERR_UNDEFINED_ERROR);
-        MON_DEBUG("command '%s' returned failure but did not pass an error\n",
-                  cmd->name);
     }
-
-#ifdef CONFIG_DEBUG_MONITOR
-    if (!ret && monitor_has_error(mon)) {
-        /*
-         * If it returns success, it must not have passed an error.
-         *
-         * Action: Report the passed error to the client.
-         */
-        MON_DEBUG("command '%s' returned success but passed an error\n",
-                  cmd->name);
-    }
-
-    if (mon_print_count_get(mon) > 0 && strcmp(cmd->name, "info") != 0) {
-        /*
-         * Handlers should not call Monitor print functions.
-         *
-         * Action: Ignore them in QMP.
-         *
-         * (XXX: we don't check any 'info' or 'query' command here
-         * because the user print function _is_ called by do_info(), hence
-         * we will trigger this check. This problem will go away when we
-         * make 'query' commands real and kill do_info())
-         */
-        MON_DEBUG("command '%s' called print functions %d time(s)\n",
-                  cmd->name, mon_print_count_get(mon));
-    }
-#endif
 }
 
 static void handle_user_command(Monitor *mon, const char *cmdline)
@@ -4449,8 +4389,6 @@ static void qmp_call_cmd(Monitor *mon, const mon_cmd_t *cmd,
     int ret;
     QObject *data = NULL;
 
-    mon_print_count_init(mon);
-
     ret = cmd->mhandler.cmd_new(mon, params, &data);
     handler_audit(mon, cmd, ret);
     monitor_protocol_emitter(mon, data);
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Luiz Capitulino
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

Make functions only used in qerror.c static.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c | 10 +++++-----
 qerror.h |  5 -----
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/qerror.c b/qerror.c
index ec4ceb8..d428b52 100644
--- a/qerror.c
+++ b/qerror.c
@@ -28,7 +28,7 @@ static const QType qerror_type = {
  *
  * Return strong reference.
  */
-QError *qerror_new(void)
+static QError *qerror_new(void)
 {
     QError *qerr;
 
@@ -116,8 +116,8 @@ static void qerror_set_desc(QError *qerr, const char *fmt)
  *
  * Return strong reference.
  */
-QError *qerror_from_info(const char *file, int linenr, const char *func,
-                         const char *fmt, va_list *va)
+static QError *qerror_from_info(const char *file, int linenr, const char *func,
+                                const char *fmt, va_list *va)
 {
     QError *qerr;
 
@@ -241,7 +241,7 @@ QString *qerror_human(const QError *qerror)
  * it uses error_report() for this, so that the output is routed to the right
  * place (ie. stderr or Monitor's device).
  */
-void qerror_print(QError *qerror)
+static void qerror_print(QError *qerror)
 {
     QString *qstring = qerror_human(qerror);
     loc_push_restore(&qerror->loc);
@@ -312,7 +312,7 @@ void assert_no_error(Error *err)
 /**
  * qobject_to_qerror(): Convert a QObject into a QError
  */
-QError *qobject_to_qerror(const QObject *obj)
+static QError *qobject_to_qerror(const QObject *obj)
 {
     if (qobject_type(obj) != QTYPE_QERROR) {
         return NULL;
diff --git a/qerror.h b/qerror.h
index b22861f..4955310 100644
--- a/qerror.h
+++ b/qerror.h
@@ -34,11 +34,7 @@ typedef struct QError {
     const QErrorStringTable *entry;
 } QError;
 
-QError *qerror_new(void);
-QError *qerror_from_info(const char *file, int linenr, const char *func,
-                         const char *fmt, va_list *va) GCC_FMT_ATTR(4, 0);
 QString *qerror_human(const QError *qerror);
-void qerror_print(QError *qerror);
 void qerror_report_internal(const char *file, int linenr, const char *func,
                             const char *fmt, ...) GCC_FMT_ATTR(4, 5);
 void qerror_report_err(Error *err);
@@ -46,6 +42,5 @@ void assert_no_error(Error *err);
 QString *qerror_format(const char *fmt, QDict *error);
 #define qerror_report(fmt, ...) \
     qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
-QError *qobject_to_qerror(const QObject *obj);
 
 #endif /* QERROR_H */
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort()
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-26 12:33   ` Markus Armbruster
  2012-07-26 12:59   ` Eric Blake
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal() Luiz Capitulino
                   ` (12 subsequent siblings)
  15 siblings, 2 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

Previously, developers had to create error dicts manually and also enter
the matching desc table entry. Thus, qerro_abort() was added to help
catching bad error dicts.

Today, all that stuff is generated automatically which makes the chance
of a bad generated dict quite low.

Also, qerror_abort() would... _abort_ on a bad error dict!

This commit maintains the same verification logic on the error object
but drops the abort() in favor of reporting UndefinedError for bad dicts
(and also print a debug message to stderr).

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c | 83 +++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 46 insertions(+), 37 deletions(-)

diff --git a/qerror.c b/qerror.c
index d428b52..74b3659 100644
--- a/qerror.c
+++ b/qerror.c
@@ -38,55 +38,50 @@ static QError *qerror_new(void)
     return qerr;
 }
 
-static void GCC_FMT_ATTR(2, 3) qerror_abort(const QError *qerr,
-                                            const char *fmt, ...)
-{
-    va_list ap;
-
-    fprintf(stderr, "qerror: bad call in function '%s':\n", qerr->func);
-    fprintf(stderr, "qerror: -> ");
-
-    va_start(ap, fmt);
-    vfprintf(stderr, fmt, ap);
-    va_end(ap);
-
-    fprintf(stderr, "\nqerror: call at %s:%d\n", qerr->file, qerr->linenr);
-    abort();
-}
-
-static void GCC_FMT_ATTR(2, 0) qerror_set_data(QError *qerr,
-                                               const char *fmt, va_list *va)
+static QDict *error_object_from_fmt(const char *fmt, va_list *va)
 {
     QObject *obj;
+    QDict *ret;
 
     obj = qobject_from_jsonv(fmt, va);
     if (!obj) {
-        qerror_abort(qerr, "invalid format '%s'", fmt);
+        fprintf(stderr, "invalid json in error dict '%s'\n", fmt);
+        return NULL;
     }
     if (qobject_type(obj) != QTYPE_QDICT) {
-        qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
+        fprintf(stderr, "error is not a dict '%s'\n", fmt);
+        goto out_free;
     }
 
-    qerr->error = qobject_to_qdict(obj);
-
-    obj = qdict_get(qerr->error, "class");
+    ret = qobject_to_qdict(obj);
+    obj = qdict_get(ret, "class");
     if (!obj) {
-        qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
+        fprintf(stderr, "missing 'class' key in '%s'\n", fmt);
+        goto out_free;
     }
     if (qobject_type(obj) != QTYPE_QSTRING) {
-        qerror_abort(qerr, "'class' key value should be a QString");
+        fprintf(stderr, "'class' key value should be a string in '%s'\n", fmt);
+        goto out_free;
     }
-    
-    obj = qdict_get(qerr->error, "data");
+
+    obj = qdict_get(ret, "data");
     if (!obj) {
-        qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
+        fprintf(stderr, "missing 'data' key in '%s'\n", fmt);
+        goto out_free;
     }
     if (qobject_type(obj) != QTYPE_QDICT) {
-        qerror_abort(qerr, "'data' key value should be a QDICT");
+        fprintf(stderr, "'data' key value should be a dict in '%s'\n", fmt);
+        goto out_free;
     }
+
+    return ret;
+
+out_free:
+    qobject_decref(obj);
+    return NULL;
 }
 
-static void qerror_set_desc(QError *qerr, const char *fmt)
+static const QErrorStringTable *error_get_desc(const char *fmt)
 {
     int i;
 
@@ -94,12 +89,17 @@ static void qerror_set_desc(QError *qerr, const char *fmt)
 
     for (i = 0; qerror_table[i].error_fmt; i++) {
         if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
-            qerr->entry = &qerror_table[i];
-            return;
+            return &qerror_table[i];
         }
     }
 
-    qerror_abort(qerr, "error format '%s' not found", fmt);
+    fprintf(stderr, "error format '%s' not found\n", fmt);
+    return NULL;
+}
+
+static QDict *build_error_no_arg(const char *fmt)
+{
+    return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
 }
 
 /**
@@ -127,13 +127,22 @@ static QError *qerror_from_info(const char *file, int linenr, const char *func,
     qerr->file = file;
     qerr->func = func;
 
-    if (!fmt) {
-        qerror_abort(qerr, "QDict not specified");
+    qerr->error = error_object_from_fmt(fmt, va);
+    if (!qerr->error) {
+        goto bad_err;
+    }
+
+    qerr->entry = error_get_desc(fmt);
+    if (!qerr->entry) {
+        QDECREF(qerr->error);
+        goto bad_err;
     }
 
-    qerror_set_data(qerr, fmt, va);
-    qerror_set_desc(qerr, fmt);
+    return qerr;
 
+bad_err:
+    qerr->error = build_error_no_arg(QERR_UNDEFINED_ERROR);
+    qerr->entry = error_get_desc(QERR_UNDEFINED_ERROR);
     return qerr;
 }
 
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal()
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (2 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-26 12:35   ` Markus Armbruster
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string Luiz Capitulino
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

It's not needed anymore and conflicts with future error improvements.

Also drops related error information, that is, the file where the error
ocurred, the line number and function. This has never been fully used.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c | 20 +++-----------------
 qerror.h |  8 +-------
 2 files changed, 4 insertions(+), 24 deletions(-)

diff --git a/qerror.c b/qerror.c
index 74b3659..8138186 100644
--- a/qerror.c
+++ b/qerror.c
@@ -105,27 +105,14 @@ static QDict *build_error_no_arg(const char *fmt)
 /**
  * qerror_from_info(): Create a new QError from error information
  *
- * The information consists of:
- *
- * - file   the file name of where the error occurred
- * - linenr the line number of where the error occurred
- * - func   the function name of where the error occurred
- * - fmt    JSON printf-like dictionary, there must exist keys 'class' and
- *          'data'
- * - va     va_list of all arguments specified by fmt
- *
  * Return strong reference.
  */
-static QError *qerror_from_info(const char *file, int linenr, const char *func,
-                                const char *fmt, va_list *va)
+static QError *qerror_from_info(const char *fmt, va_list *va)
 {
     QError *qerr;
 
     qerr = qerror_new();
     loc_save(&qerr->loc);
-    qerr->linenr = linenr;
-    qerr->file = file;
-    qerr->func = func;
 
     qerr->error = error_object_from_fmt(fmt, va);
     if (!qerr->error) {
@@ -259,14 +246,13 @@ static void qerror_print(QError *qerror)
     QDECREF(qstring);
 }
 
-void qerror_report_internal(const char *file, int linenr, const char *func,
-                            const char *fmt, ...)
+void qerror_report(const char *fmt, ...)
 {
     va_list va;
     QError *qerror;
 
     va_start(va, fmt);
-    qerror = qerror_from_info(file, linenr, func, fmt, &va);
+    qerror = qerror_from_info(fmt, &va);
     va_end(va);
 
     if (monitor_cur_is_qmp()) {
diff --git a/qerror.h b/qerror.h
index 4955310..929017c 100644
--- a/qerror.h
+++ b/qerror.h
@@ -28,19 +28,13 @@ typedef struct QError {
     QObject_HEAD;
     QDict *error;
     Location loc;
-    int linenr;
-    const char *file;
-    const char *func;
     const QErrorStringTable *entry;
 } QError;
 
 QString *qerror_human(const QError *qerror);
-void qerror_report_internal(const char *file, int linenr, const char *func,
-                            const char *fmt, ...) GCC_FMT_ATTR(4, 5);
+void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void qerror_report_err(Error *err);
 void assert_no_error(Error *err);
 QString *qerror_format(const char *fmt, QDict *error);
-#define qerror_report(fmt, ...) \
-    qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
 
 #endif /* QERROR_H */
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (3 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal() Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction Luiz Capitulino
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

Simplifies current and future users.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 error.c  |  5 +----
 qerror.c | 10 ++++++++--
 qerror.h |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/error.c b/error.c
index a52b771..b630b05 100644
--- a/error.c
+++ b/error.c
@@ -64,10 +64,7 @@ bool error_is_set(Error **errp)
 const char *error_get_pretty(Error *err)
 {
     if (err->msg == NULL) {
-        QString *str;
-        str = qerror_format(err->fmt, err->obj);
-        err->msg = g_strdup(qstring_get_str(str));
-        QDECREF(str);
+        err->msg = qerror_format(err->fmt, err->obj);
     }
 
     return err->msg;
diff --git a/qerror.c b/qerror.c
index 8138186..7db28fc 100644
--- a/qerror.c
+++ b/qerror.c
@@ -207,9 +207,11 @@ static QString *qerror_format_desc(QDict *error,
     return qstring;
 }
 
-QString *qerror_format(const char *fmt, QDict *error)
+char *qerror_format(const char *fmt, QDict *error)
 {
     const QErrorStringTable *entry = NULL;
+    QString *qstr;
+    char *ret;
     int i;
 
     for (i = 0; qerror_table[i].error_fmt; i++) {
@@ -219,7 +221,11 @@ QString *qerror_format(const char *fmt, QDict *error)
         }
     }
 
-    return qerror_format_desc(error, entry);
+    qstr = qerror_format_desc(error, entry);
+    ret = g_strdup(qstring_get_str(qstr));
+    QDECREF(qstr);
+
+    return ret;
 }
 
 /**
diff --git a/qerror.h b/qerror.h
index 929017c..6bf941b 100644
--- a/qerror.h
+++ b/qerror.h
@@ -35,6 +35,6 @@ QString *qerror_human(const QError *qerror);
 void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void qerror_report_err(Error *err);
 void assert_no_error(Error *err);
-QString *qerror_format(const char *fmt, QDict *error);
+char *qerror_format(const char *fmt, QDict *error);
 
 #endif /* QERROR_H */
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (4 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 07/14] error: " Luiz Capitulino
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

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 eliminates the need of storing a pointer to qerror_table[], which
will be dropped soon, and also simplifies the code.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c | 34 +++++++---------------------------
 qerror.h |  2 +-
 2 files changed, 8 insertions(+), 28 deletions(-)

diff --git a/qerror.c b/qerror.c
index 7db28fc..89def8d 100644
--- a/qerror.c
+++ b/qerror.c
@@ -81,22 +81,6 @@ out_free:
     return NULL;
 }
 
-static const QErrorStringTable *error_get_desc(const char *fmt)
-{
-    int i;
-
-    // FIXME: inefficient loop
-
-    for (i = 0; qerror_table[i].error_fmt; i++) {
-        if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
-            return &qerror_table[i];
-        }
-    }
-
-    fprintf(stderr, "error format '%s' not found\n", fmt);
-    return NULL;
-}
-
 static QDict *build_error_no_arg(const char *fmt)
 {
     return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
@@ -119,8 +103,8 @@ static QError *qerror_from_info(const char *fmt, va_list *va)
         goto bad_err;
     }
 
-    qerr->entry = error_get_desc(fmt);
-    if (!qerr->entry) {
+    qerr->err_msg = qerror_format(fmt, qerr->error);
+    if (!qerr->err_msg) {
         QDECREF(qerr->error);
         goto bad_err;
     }
@@ -129,7 +113,7 @@ static QError *qerror_from_info(const char *fmt, va_list *va)
 
 bad_err:
     qerr->error = build_error_no_arg(QERR_UNDEFINED_ERROR);
-    qerr->entry = error_get_desc(QERR_UNDEFINED_ERROR);
+    qerr->err_msg = qerror_format(QERR_UNDEFINED_ERROR, qerr->error);
     return qerr;
 }
 
@@ -233,7 +217,7 @@ char *qerror_format(const char *fmt, QDict *error)
  */
 QString *qerror_human(const QError *qerror)
 {
-    return qerror_format_desc(qerror->error, qerror->entry);
+    return qstring_from_str(qerror->err_msg);
 }
 
 /**
@@ -280,19 +264,14 @@ struct Error
 void qerror_report_err(Error *err)
 {
     QError *qerr;
-    int i;
 
     qerr = qerror_new();
     loc_save(&qerr->loc);
     QINCREF(err->obj);
     qerr->error = err->obj;
 
-    for (i = 0; qerror_table[i].error_fmt; i++) {
-        if (strcmp(qerror_table[i].error_fmt, err->fmt) == 0) {
-            qerr->entry = &qerror_table[i];
-            break;
-        }
-    }
+    qerr->err_msg = qerror_format(err->fmt, qerr->error);
+    /* FIXME: should report UndefinedError on error */
 
     if (monitor_cur_is_qmp()) {
         monitor_set_error(cur_mon, qerr);
@@ -333,5 +312,6 @@ static void qerror_destroy_obj(QObject *obj)
     qerr = qobject_to_qerror(obj);
 
     QDECREF(qerr->error);
+    g_free(qerr->err_msg);
     g_free(qerr);
 }
diff --git a/qerror.h b/qerror.h
index 6bf941b..16401ff 100644
--- a/qerror.h
+++ b/qerror.h
@@ -28,7 +28,7 @@ typedef struct QError {
     QObject_HEAD;
     QDict *error;
     Location loc;
-    const QErrorStringTable *entry;
+    char *err_msg;
 } QError;
 
 QString *qerror_human(const QError *qerror);
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 07/14] error: don't delay error message construction
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (5 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[] Luiz Capitulino
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

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>
---
 error.c  | 8 +-------
 qerror.c | 4 +---
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/error.c b/error.c
index b630b05..acb10a2 100644
--- a/error.c
+++ b/error.c
@@ -20,7 +20,6 @@
 struct Error
 {
     QDict *obj;
-    const char *fmt;
     char *msg;
 };
 
@@ -38,7 +37,7 @@ void error_set(Error **errp, const char *fmt, ...)
     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;
 }
@@ -49,7 +48,6 @@ Error *error_copy(const Error *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);
 
@@ -63,10 +61,6 @@ bool error_is_set(Error **errp)
 
 const char *error_get_pretty(Error *err)
 {
-    if (err->msg == NULL) {
-        err->msg = qerror_format(err->fmt, err->obj);
-    }
-
     return err->msg;
 }
 
diff --git a/qerror.c b/qerror.c
index 89def8d..42e8687 100644
--- a/qerror.c
+++ b/qerror.c
@@ -257,7 +257,6 @@ void qerror_report(const char *fmt, ...)
 struct Error
 {
     QDict *obj;
-    const char *fmt;
     char *msg;
 };
 
@@ -270,8 +269,7 @@ void qerror_report_err(Error *err)
     QINCREF(err->obj);
     qerr->error = err->obj;
 
-    qerr->err_msg = qerror_format(err->fmt, qerr->error);
-    /* FIXME: should report UndefinedError on error */
+    qerr->err_msg = g_strdup(err->msg);
 
     if (monitor_cur_is_qmp()) {
         monitor_set_error(cur_mon, qerr);
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[]
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (6 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 07/14] error: " Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-26 12:52   ` Markus Armbruster
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message Luiz Capitulino
                   ` (7 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

In the near future, the QERR_ macros (which are json strings today) will
be turned into an enumeration. When we get there, build_error_dict()
will be used to (guess what) build an error dict by:

 1. Using the error class as an index to error_object_table[], which
    contains all QMP errors as json strings (with default values)

 2. Use the human error string to construct the error object data member.
    For example, an error message like:

     "Parameter name=brain has not been found"

     Will construct the following data member:

     'data': { 'name': 'brain' } }

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c               | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++
 qerror.h               |  1 +
 scripts/qapi-errors.py | 39 +++++++++++++++++++++++
 3 files changed, 126 insertions(+)

diff --git a/qerror.c b/qerror.c
index 42e8687..267545e 100644
--- a/qerror.c
+++ b/qerror.c
@@ -38,6 +38,92 @@ static QError *qerror_new(void)
     return qerr;
 }
 
+static bool iscchar(int c)
+{
+    return (isalpha(c) || isdigit(c) || c == '_');
+}
+
+static char *get_key(const char *str)
+{
+    char *p, *ret;
+
+    ret = p = g_strdup(str);
+
+    while (!iscchar(*p)) {
+        p++;
+    }
+    memmove(ret, p, strlen(ret));
+
+    p = ret;
+    while (iscchar(*p)) {
+        p++;
+    }
+    *p = '\0';
+
+    return ret;
+}
+
+static char *get_value(const char *str)
+{
+    char *p, *ret;
+
+    p = strchr(str, '=');
+    while (!iscchar(*p)) {
+        p++;
+    }
+    p = ret = g_strdup(p);
+    while (iscchar(*p)) {
+        p++;
+    }
+    *p = '\0';
+
+    return ret;
+}
+
+static void set_dict_data(const char *msg, QDict *data_dict)
+{
+    char *str, *msg2, *saveptr = NULL;
+
+    msg2 = g_strdup(msg);
+    str = strtok_r(msg2, " ", &saveptr);
+    while (str) {
+        if (strchr(str, '=')) {
+            char *key = get_key(str);
+            char *value = get_value(str);
+
+            /* FIXME: handle ints */
+            if (qdict_haskey(data_dict, key)) {
+                qdict_put(data_dict, key, qstring_from_str(value));
+            }
+
+            g_free(key);
+            g_free(value);
+        }
+        str = strtok_r(NULL, " ", &saveptr);
+    }
+
+    g_free(msg2);
+}
+
+QDict *build_error_dict(int err_class, const char *msg)
+{
+    QDict *err_dict;
+    QObject *obj;
+
+    assert(msg[0] != '\0');
+
+    obj = qobject_from_json(error_object_table[err_class]);
+    assert(obj);
+    assert(qobject_type(obj) == QTYPE_QDICT);
+
+    err_dict = qobject_to_qdict(obj);
+    assert(qdict_haskey(err_dict, "data"));
+
+    set_dict_data(msg, qdict_get_qdict(err_dict, "data"));
+
+    return err_dict;
+}
+
 static QDict *error_object_from_fmt(const char *fmt, va_list *va)
 {
     QObject *obj;
diff --git a/qerror.h b/qerror.h
index 16401ff..c4f6053 100644
--- a/qerror.h
+++ b/qerror.h
@@ -36,5 +36,6 @@ void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void qerror_report_err(Error *err);
 void assert_no_error(Error *err);
 char *qerror_format(const char *fmt, QDict *error);
+QDict *build_error_dict(int err_class, const char *msg);
 
 #endif /* QERROR_H */
diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
index 59cf426..5f8723e 100644
--- a/scripts/qapi-errors.py
+++ b/scripts/qapi-errors.py
@@ -85,6 +85,42 @@ static const QErrorStringTable qerror_table[] = {
 
     return ret
 
+def gen_error_data_obj(data):
+    colon = ''
+    data_str = ''
+    for k, v in data.items():
+        data_str += colon + "'%s': " % k
+        if v == 'str':
+            data_str += "'unknown'"
+        elif v == 'int':
+            data_str += '0'
+        else:
+            sys.exit("unknown data type '%s' for error '%s'" % (v, name))
+        colon = ', '
+    return data_str
+
+def gen_error_obj_table(exprs):
+    ret = mcgen('''
+static const char *error_object_table[] = {
+''')
+
+    for err in exprs:
+        data = gen_error_data_obj({})
+        if err.has_key('data'):
+            data = gen_error_data_obj(err['data'])
+        ret += mcgen('''
+    "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }",
+''',
+                error_class=err['error'], error_data=data)
+
+    ret += mcgen('''
+    NULL,
+};
+
+''')
+
+    return ret;
+
 def gen_error_macro_data_str(data):
     colon = ''
     data_str = ''
@@ -173,5 +209,8 @@ if __name__ == '__main__':
     ret = gen_error_def_table(exprs)
     fdef.write(ret)
 
+    ret = gen_error_obj_table(exprs)
+    fdef.write(ret)
+
     fdef.flush()
     fdef.close()
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (7 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[] Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 10/14] error: error_set(): " Luiz Capitulino
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

This commit does three indivisible changes:

1. qerror_report() is changed to take an index to error_object_table[]
   and a human error message in printf format.

   That is, we go from:

        qerror_report(const char *fmt, ...);

        where fmt is a json dict in string format and the arguments
        are error data (the data member in qapi-schema-error.json).

    To:

        qerror_report(int err_class, const char *fmt, ...);

        where err_class is the error_object_table[] index, and the
        remaining arguments form a printf-like string, which is going
        to be used as the human error message.

    Future commits will turn the index into a proper enumeration.

    qerror_report() is also changed to use build_error_dict(), which
    was introduced by the last commit.

2. error_object_from_fmt(), which was used to build the error object
   from the previous 'fmt' argument is dropped

3. All calls to qerror_report() are changed to adhere to the new
   signature. As an example, a call like:

        qerror_report(QERR_DEVICE_IN_USE, device);

    is changed to:

         qerror_report(/* QERR_DEVICE_IN_USE */ 14,
                        "Device 'device=%s' is in use", device);

    The name in the comment is going to be the future enum for the
    index used.

TODO: fix long lines.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 block/cow.c       |  3 +--
 block/qcow.c      |  3 +--
 block/qcow2.c     |  3 +--
 block/qed.c       |  3 +--
 blockdev.c        | 10 ++++----
 hw/pci.c          |  4 +--
 hw/qdev-monitor.c | 24 +++++++++---------
 hw/usb/bus.c      |  3 +--
 hw/usb/hcd-ehci.c |  6 ++---
 hw/usb/redirect.c |  5 ++--
 monitor.c         | 55 ++++++++++++++++++-----------------------
 qemu-option.c     |  2 +-
 qerror.c          | 73 ++++++-------------------------------------------------
 qerror.h          |  2 +-
 14 files changed, 60 insertions(+), 136 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index a5a00eb..002dcf1 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -81,8 +81,7 @@ static int cow_open(BlockDriverState *bs, int flags)
         char version[64];
         snprintf(version, sizeof(version),
                "COW version %d", cow_header.version);
-        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-            bs->device_name, "cow", version);
+        qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "cow", version);
         ret = -ENOTSUP;
         goto fail;
     }
diff --git a/block/qcow.c b/block/qcow.c
index 7b5ab87..e820099 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -118,8 +118,7 @@ static int qcow_open(BlockDriverState *bs, int flags)
     if (header.version != QCOW_VERSION) {
         char version[64];
         snprintf(version, sizeof(version), "QCOW version %d", header.version);
-        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-            bs->device_name, "qcow", version);
+        qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "qcow", version);
         ret = -ENOTSUP;
         goto fail;
     }
diff --git a/block/qcow2.c b/block/qcow2.c
index 870148d..a5b46df 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -192,8 +192,7 @@ static void GCC_FMT_ATTR(2, 3) report_unsupported(BlockDriverState *bs,
     vsnprintf(msg, sizeof(msg), fmt, ap);
     va_end(ap);
 
-    qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-        bs->device_name, "qcow2", msg);
+    qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "qcow2", msg);
 }
 
 static void report_unsupported_feature(BlockDriverState *bs,
diff --git a/block/qed.c b/block/qed.c
index 5f3eefa..fda3dcc 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -397,8 +397,7 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags)
         char buf[64];
         snprintf(buf, sizeof(buf), "%" PRIx64,
             s->header.features & ~QED_FEATURE_MASK);
-        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
-            bs->device_name, "QED", buf);
+        qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "QED", buf);
         return -ENOTSUP;
     }
     if (!qed_is_cluster_size_valid(s->header.cluster_size)) {
diff --git a/blockdev.c b/blockdev.c
index 3d75015..6060c88 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -633,18 +633,18 @@ void do_commit(Monitor *mon, const QDict *qdict)
     if (!strcmp(device, "all")) {
         ret = bdrv_commit_all();
         if (ret == -EBUSY) {
-            qerror_report(QERR_DEVICE_IN_USE, device);
+            qerror_report(/* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
             return;
         }
     } else {
         bs = bdrv_find(device);
         if (!bs) {
-            qerror_report(QERR_DEVICE_NOT_FOUND, device);
+            qerror_report(/* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
             return;
         }
         ret = bdrv_commit(bs);
         if (ret == -EBUSY) {
-            qerror_report(QERR_DEVICE_IN_USE, device);
+            qerror_report(/* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
             return;
         }
     }
@@ -985,11 +985,11 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 
     bs = bdrv_find(id);
     if (!bs) {
-        qerror_report(QERR_DEVICE_NOT_FOUND, id);
+        qerror_report(/* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", id);
         return -1;
     }
     if (bdrv_in_use(bs)) {
-        qerror_report(QERR_DEVICE_IN_USE, id);
+        qerror_report(/* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", id);
         return -1;
     }
 
diff --git a/hw/pci.c b/hw/pci.c
index 99a4304..1aac667 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1506,7 +1506,7 @@ static int pci_qdev_init(DeviceState *qdev)
     if (pci_dev == NULL)
         return -1;
     if (qdev->hotplugged && pc->no_hotplug) {
-        qerror_report(QERR_DEVICE_NO_HOTPLUG, object_get_typename(OBJECT(pci_dev)));
+        qerror_report(/* QERR_DEVICE_NO_HOTPLUG */ 19, "Device 'device=%s' does not support hotplugging", object_get_typename(OBJECT(pci_dev)));
         do_pci_unregister_device(pci_dev);
         return -1;
     }
@@ -1547,7 +1547,7 @@ static int pci_unplug_device(DeviceState *qdev)
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
 
     if (pc->no_hotplug) {
-        qerror_report(QERR_DEVICE_NO_HOTPLUG, object_get_typename(OBJECT(dev)));
+        qerror_report(/* QERR_DEVICE_NO_HOTPLUG */ 19, "Device 'device=%s' does not support hotplugging", object_get_typename(OBJECT(dev)));
         return -1;
     }
     return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 7915b45..db2ed77 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -326,7 +326,7 @@ static BusState *qbus_find(const char *path)
         }
         bus = qbus_find_recursive(sysbus_get_default(), elem, NULL);
         if (!bus) {
-            qerror_report(QERR_BUS_NOT_FOUND, elem);
+            qerror_report(/* QERR_BUS_NOT_FOUND */ 7, "Bus 'bus=%s' not found", elem);
             return NULL;
         }
         pos = len;
@@ -349,7 +349,7 @@ static BusState *qbus_find(const char *path)
         pos += len;
         dev = qbus_find_dev(bus, elem);
         if (!dev) {
-            qerror_report(QERR_DEVICE_NOT_FOUND, elem);
+            qerror_report(/* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", elem);
             if (!monitor_cur_is_qmp()) {
                 qbus_list_dev(bus);
             }
@@ -365,12 +365,12 @@ static BusState *qbus_find(const char *path)
              * one child bus accept it nevertheless */
             switch (dev->num_child_bus) {
             case 0:
-                qerror_report(QERR_DEVICE_NO_BUS, elem);
+                qerror_report(/* QERR_DEVICE_NO_BUS */ 18, "Device 'device=%s' has no child bus", elem);
                 return NULL;
             case 1:
                 return QLIST_FIRST(&dev->child_bus);
             default:
-                qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem);
+                qerror_report(/* QERR_DEVICE_MULTIPLE_BUSSES */ 17, "Device 'device=%s' has multiple child busses", elem);
                 if (!monitor_cur_is_qmp()) {
                     qbus_list_bus(dev);
                 }
@@ -386,7 +386,7 @@ static BusState *qbus_find(const char *path)
         pos += len;
         bus = qbus_find_bus(dev, elem);
         if (!bus) {
-            qerror_report(QERR_BUS_NOT_FOUND, elem);
+            qerror_report(/* QERR_BUS_NOT_FOUND */ 7, "Bus 'bus=%s' not found", elem);
             if (!monitor_cur_is_qmp()) {
                 qbus_list_bus(dev);
             }
@@ -405,7 +405,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 
     driver = qemu_opt_get(opts, "driver");
     if (!driver) {
-        qerror_report(QERR_MISSING_PARAMETER, "driver");
+        qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "driver");
         return NULL;
     }
 
@@ -421,7 +421,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
 
     if (!obj) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
+        qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "driver", "device type");
         return NULL;
     }
 
@@ -435,20 +435,18 @@ DeviceState *qdev_device_add(QemuOpts *opts)
             return NULL;
         }
         if (strcmp(object_get_typename(OBJECT(bus)), k->bus_type) != 0) {
-            qerror_report(QERR_BAD_BUS_FOR_DEVICE,
-                          driver, object_get_typename(OBJECT(bus)));
+            qerror_report(/* QERR_BAD_BUS_FOR_DEVICE */ 2, "Device 'device=%s' can't go on a bad_bus_type=%s bus", driver, object_get_typename(OBJECT(bus)));
             return NULL;
         }
     } else {
         bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type);
         if (!bus) {
-            qerror_report(QERR_NO_BUS_FOR_DEVICE,
-                          driver, k->bus_type);
+            qerror_report(/* QERR_NO_BUS_FOR_DEVICE */ 43, "No 'bus=%s' bus found for device 'device=%s'", driver, k->bus_type);
             return NULL;
         }
     }
     if (qdev_hotplug && !bus->allow_hotplug) {
-        qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
+        qerror_report(/* QERR_BUS_NO_HOTPLUG */ 6, "Bus 'bus=%s' does not support hotplugging", bus->name);
         return NULL;
     }
 
@@ -479,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         g_free(name);
     }        
     if (qdev_init(qdev) < 0) {
-        qerror_report(QERR_DEVICE_INIT_FAILED, driver);
+        qerror_report(/* QERR_DEVICE_INIT_FAILED */ 13, "Device 'device=%s' could not be initialized", driver);
         return NULL;
     }
     qdev->opts = opts;
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index b649360..28901cb 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -303,8 +303,7 @@ int usb_register_companion(const char *masterbus, USBPort *ports[],
     }
 
     if (!bus || !bus->ops->register_companion) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus",
-                      "an USB masterbus");
+        qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "masterbus", "an USB masterbus");
         if (bus) {
             error_printf_unless_qmp(
                 "USB bus '%s' does not allow companion controllers\n",
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index b043e7c..2d42945 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -933,8 +933,7 @@ static int ehci_register_companion(USBBus *bus, USBPort *ports[],
     uint32_t i;
 
     if (firstport + portcount > NB_PORTS) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "firstport",
-                      "firstport on masterbus");
+        qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "firstport", "firstport on masterbus");
         error_printf_unless_qmp(
             "firstport value of %u makes companion take ports %u - %u, which "
             "is outside of the valid range of 0 - %u\n", firstport, firstport,
@@ -944,8 +943,7 @@ static int ehci_register_companion(USBBus *bus, USBPort *ports[],
 
     for (i = 0; i < portcount; i++) {
         if (s->companion_ports[firstport + i]) {
-            qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus",
-                          "an USB masterbus");
+            qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "masterbus", "an USB masterbus");
             error_printf_unless_qmp(
                 "port %u on masterbus %s already has a companion assigned\n",
                 firstport + i, bus->qbus.name);
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 10b4fbb..d43dae2 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -902,7 +902,7 @@ static int usbredir_initfn(USBDevice *udev)
     int i;
 
     if (dev->cs == NULL) {
-        qerror_report(QERR_MISSING_PARAMETER, "chardev");
+        qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "chardev");
         return -1;
     }
 
@@ -911,8 +911,7 @@ static int usbredir_initfn(USBDevice *udev)
                                            &dev->filter_rules,
                                            &dev->filter_rules_count);
         if (i) {
-            qerror_report(QERR_INVALID_PARAMETER_VALUE, "filter",
-                          "a usb device filter string");
+            qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "filter", "a usb device filter string");
             return -1;
         }
     }
diff --git a/monitor.c b/monitor.c
index c22cfca..0ccca3b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -227,7 +227,7 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
                           void *opaque)
 {
     if (monitor_ctrl_mode(mon)) {
-        qerror_report(QERR_MISSING_PARAMETER, "password");
+        qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "password");
         return -EINVAL;
     } else if (mon->rs) {
         readline_start(mon->rs, "Password: ", 1, readline_func, opaque);
@@ -936,7 +936,7 @@ static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_d
         int tls = qdict_get_try_bool(qdict, "tls", 0);
         if (!using_spice) {
             /* correct one? spice isn't a device ,,, */
-            qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
+            qerror_report(/* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
             return -1;
         }
         if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
@@ -953,13 +953,13 @@ static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_d
     } else if ((s = qemu_chr_find(protocol)) != NULL) {
 	int fd = monitor_get_fd(mon, fdname);
 	if (qemu_chr_add_client(s, fd) < 0) {
-	    qerror_report(QERR_ADD_CLIENT_FAILED);
+qerror_report(/* QERR_ADD_CLIENT_FAILED */ 0, "Could not add client");
 	    return -1;
 	}
 	return 0;
     }
 
-    qerror_report(QERR_INVALID_PARAMETER, "protocol");
+    qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
     return -1;
 }
 
@@ -975,25 +975,25 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
 
     if (strcmp(protocol, "spice") == 0) {
         if (!using_spice) {
-            qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
+            qerror_report(/* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
             return -1;
         }
 
         if (port == -1 && tls_port == -1) {
-            qerror_report(QERR_MISSING_PARAMETER, "port/tls-port");
+            qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "port/tls-port");
             return -1;
         }
 
         ret = qemu_spice_migrate_info(hostname, port, tls_port, subject,
                                       cb, opaque);
         if (ret != 0) {
-            qerror_report(QERR_UNDEFINED_ERROR);
+            qerror_report(/* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
             return -1;
         }
         return 0;
     }
 
-    qerror_report(QERR_INVALID_PARAMETER, "protocol");
+    qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
     return -1;
 }
 
@@ -3859,7 +3859,7 @@ static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
          *
          * Action: Report an internal error to the client if in QMP.
          */
-        qerror_report(QERR_UNDEFINED_ERROR);
+        qerror_report(/* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
     }
 }
 
@@ -4162,7 +4162,7 @@ static int check_client_args_type(const QDict *client_args,
                 continue;
             }
             /* client arg doesn't exist */
-            qerror_report(QERR_INVALID_PARAMETER, client_arg_name);
+            qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", client_arg_name);
             return -1;
         }
 
@@ -4175,8 +4175,7 @@ static int check_client_args_type(const QDict *client_args,
         case 'B':
         case 's':
             if (qobject_type(client_arg) != QTYPE_QSTRING) {
-                qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
-                              "string");
+                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "string");
                 return -1;
             }
         break;
@@ -4185,24 +4184,21 @@ static int check_client_args_type(const QDict *client_args,
         case 'M':
         case 'o':
             if (qobject_type(client_arg) != QTYPE_QINT) {
-                qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
-                              "int");
+                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "int");
                 return -1; 
             }
             break;
         case 'T':
             if (qobject_type(client_arg) != QTYPE_QINT &&
                 qobject_type(client_arg) != QTYPE_QFLOAT) {
-                qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
-                              "number");
+                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "number");
                return -1; 
             }
             break;
         case 'b':
         case '-':
             if (qobject_type(client_arg) != QTYPE_QBOOL) {
-                qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
-                              "bool");
+                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "bool");
                return -1; 
             }
             break;
@@ -4246,7 +4242,7 @@ static int check_mandatory_args(const QDict *cmd_args,
         } else if (qstring_get_str(type)[0] != '-' &&
                    qstring_get_str(type)[1] != '?' &&
                    !qdict_haskey(client_args, cmd_arg_name)) {
-            qerror_report(QERR_MISSING_PARAMETER, cmd_arg_name);
+            qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", cmd_arg_name);
             return -1;
         }
     }
@@ -4344,7 +4340,7 @@ static QDict *qmp_check_input_obj(QObject *input_obj)
     QDict *input_dict;
 
     if (qobject_type(input_obj) != QTYPE_QDICT) {
-        qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "object");
+        qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "object");
         return NULL;
     }
 
@@ -4356,27 +4352,25 @@ static QDict *qmp_check_input_obj(QObject *input_obj)
 
         if (!strcmp(arg_name, "execute")) {
             if (qobject_type(arg_obj) != QTYPE_QSTRING) {
-                qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "execute",
-                              "string");
+                qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT_MEMBER */ 56, "QMP input object member 'member=%s' expects 'expected=%s'", "execute", "string");
                 return NULL;
             }
             has_exec_key = 1;
         } else if (!strcmp(arg_name, "arguments")) {
             if (qobject_type(arg_obj) != QTYPE_QDICT) {
-                qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "arguments",
-                              "object");
+                qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT_MEMBER */ 56, "QMP input object member 'member=%s' expects 'expected=%s'", "arguments", "object");
                 return NULL;
             }
         } else if (!strcmp(arg_name, "id")) {
             /* FIXME: check duplicated IDs for async commands */
         } else {
-            qerror_report(QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER, arg_name);
+            qerror_report(/* QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER */ 57, "QMP input object member 'member=%s' is unexpected", arg_name);
             return NULL;
         }
     }
 
     if (!has_exec_key) {
-        qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "execute");
+        qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "execute");
         return NULL;
     }
 
@@ -4409,7 +4403,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     obj = json_parser_parse(tokens, NULL);
     if (!obj) {
         // FIXME: should be triggered in json_parser_parse()
-        qerror_report(QERR_JSON_PARSING);
+        qerror_report(/* QERR_JSON_PARSING */ 37, "Invalid JSON syntax");
         goto err_out;
     }
 
@@ -4425,13 +4419,13 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     cmd_name = qdict_get_str(input, "execute");
     trace_handle_qmp_command(mon, cmd_name);
     if (invalid_qmp_mode(mon, cmd_name)) {
-        qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
+        qerror_report(/* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", cmd_name);
         goto err_out;
     }
 
     cmd = qmp_find_cmd(cmd_name);
     if (!cmd) {
-        qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
+        qerror_report(/* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", cmd_name);
         goto err_out;
     }
 
@@ -4693,8 +4687,7 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
     }
 
     if (monitor_ctrl_mode(mon)) {
-        qerror_report(QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs),
-                      bdrv_get_encrypted_filename(bs));
+        qerror_report(/* QERR_DEVICE_ENCRYPTED */ 10, "Device 'device=%s' is encrypted (filename=filename=%s)", bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs));
         return -1;
     }
 
diff --git a/qemu-option.c b/qemu-option.c
index bb3886c..a351ed9 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -690,7 +690,7 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
         if (i == 0) {
             /* empty list -> allow any */;
         } else {
-            qerror_report(QERR_INVALID_PARAMETER, name);
+            qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", name);
             return -1;
         }
     }
diff --git a/qerror.c b/qerror.c
index 267545e..6d61426 100644
--- a/qerror.c
+++ b/qerror.c
@@ -124,82 +124,23 @@ QDict *build_error_dict(int err_class, const char *msg)
     return err_dict;
 }
 
-static QDict *error_object_from_fmt(const char *fmt, va_list *va)
-{
-    QObject *obj;
-    QDict *ret;
-
-    obj = qobject_from_jsonv(fmt, va);
-    if (!obj) {
-        fprintf(stderr, "invalid json in error dict '%s'\n", fmt);
-        return NULL;
-    }
-    if (qobject_type(obj) != QTYPE_QDICT) {
-        fprintf(stderr, "error is not a dict '%s'\n", fmt);
-        goto out_free;
-    }
-
-    ret = qobject_to_qdict(obj);
-    obj = qdict_get(ret, "class");
-    if (!obj) {
-        fprintf(stderr, "missing 'class' key in '%s'\n", fmt);
-        goto out_free;
-    }
-    if (qobject_type(obj) != QTYPE_QSTRING) {
-        fprintf(stderr, "'class' key value should be a string in '%s'\n", fmt);
-        goto out_free;
-    }
-
-    obj = qdict_get(ret, "data");
-    if (!obj) {
-        fprintf(stderr, "missing 'data' key in '%s'\n", fmt);
-        goto out_free;
-    }
-    if (qobject_type(obj) != QTYPE_QDICT) {
-        fprintf(stderr, "'data' key value should be a dict in '%s'\n", fmt);
-        goto out_free;
-    }
-
-    return ret;
-
-out_free:
-    qobject_decref(obj);
-    return NULL;
-}
-
-static QDict *build_error_no_arg(const char *fmt)
-{
-    return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
-}
-
 /**
  * qerror_from_info(): Create a new QError from error information
  *
  * Return strong reference.
  */
-static QError *qerror_from_info(const char *fmt, va_list *va)
+static QError *qerror_from_info(int err_class, const char *fmt, va_list *va)
 {
     QError *qerr;
+    char msg[2048];
 
     qerr = qerror_new();
     loc_save(&qerr->loc);
 
-    qerr->error = error_object_from_fmt(fmt, va);
-    if (!qerr->error) {
-        goto bad_err;
-    }
-
-    qerr->err_msg = qerror_format(fmt, qerr->error);
-    if (!qerr->err_msg) {
-        QDECREF(qerr->error);
-        goto bad_err;
-    }
-
-    return qerr;
+    vsnprintf(msg, sizeof(msg), fmt, *va);
+    qerr->err_msg = g_strdup(msg);
+    qerr->error = build_error_dict(err_class, qerr->err_msg);
 
-bad_err:
-    qerr->error = build_error_no_arg(QERR_UNDEFINED_ERROR);
-    qerr->err_msg = qerror_format(QERR_UNDEFINED_ERROR, qerr->error);
     return qerr;
 }
 
@@ -322,13 +263,13 @@ static void qerror_print(QError *qerror)
     QDECREF(qstring);
 }
 
-void qerror_report(const char *fmt, ...)
+void qerror_report(int err_class, const char *fmt, ...)
 {
     va_list va;
     QError *qerror;
 
     va_start(va, fmt);
-    qerror = qerror_from_info(fmt, &va);
+    qerror = qerror_from_info(err_class, fmt, &va);
     va_end(va);
 
     if (monitor_cur_is_qmp()) {
diff --git a/qerror.h b/qerror.h
index c4f6053..32e9a22 100644
--- a/qerror.h
+++ b/qerror.h
@@ -32,7 +32,7 @@ typedef struct QError {
 } QError;
 
 QString *qerror_human(const QError *qerror);
-void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void qerror_report(int err_class, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 void qerror_report_err(Error *err);
 void assert_no_error(Error *err);
 char *qerror_format(const char *fmt, QDict *error);
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 10/14] error: error_set(): take an index and a human error message
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (8 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good Luiz Capitulino
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

This commit does for error_set() the same change that last commit did
for qerror_report().

TODO: fix long lines.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 balloon.c                   | 10 +++---
 block.c                     |  4 +--
 block/qcow.c                |  4 +--
 block/stream.c              |  2 +-
 block/vdi.c                 |  4 +--
 block/vmdk.c                |  4 +--
 block/vpc.c                 |  4 +--
 block/vvfat.c               |  4 +--
 blockdev.c                  | 69 ++++++++++++++++++++-------------------
 cpus.c                      | 13 ++++----
 dump-stub.c                 |  2 +-
 dump.c                      | 18 +++++------
 error.c                     | 12 +++++--
 error.h                     |  2 +-
 hmp.c                       |  2 +-
 hw/9pfs/virtio-9p.c         |  3 +-
 hw/ivshmem.c                |  2 +-
 hw/pci-stub.c               |  2 +-
 hw/qdev-addr.c              |  6 ++--
 hw/qdev-monitor.c           |  2 +-
 hw/qdev-properties.c        | 49 ++++++++++++----------------
 hw/qdev.c                   |  6 ++--
 json-parser.c               |  2 +-
 migration.c                 |  6 ++--
 monitor.c                   | 10 +++---
 net.c                       | 20 ++++++------
 qapi/qapi-visit-core.c      | 22 +++++--------
 qapi/qmp-dispatch.c         | 14 ++++----
 qapi/qmp-input-visitor.c    | 22 +++++--------
 qapi/string-input-visitor.c | 12 +++----
 qemu-config.c               |  2 +-
 qemu-ga.c                   |  4 +--
 qemu-option.c               | 18 +++++------
 qemu-sockets.c              | 22 ++++++-------
 qga/commands-posix.c        | 78 ++++++++++++++++++++++-----------------------
 qga/commands-win32.c        | 53 +++++++++++++-----------------
 qmp.c                       | 47 +++++++++++++--------------
 qom/object.c                | 20 ++++++------
 savevm.c                    |  6 ++--
 target-i386/cpu.c           | 15 +++------
 ui/vnc.c                    |  4 +--
 41 files changed, 273 insertions(+), 328 deletions(-)

diff --git a/balloon.c b/balloon.c
index e02ab1c..a8bf9b6 100644
--- a/balloon.c
+++ b/balloon.c
@@ -99,14 +99,14 @@ BalloonInfo *qmp_query_balloon(Error **errp)
     BalloonInfo *info;
 
     if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+        error_set(errp, /* QERR_KVM_MISSING_CAP */ 38, "Using KVM without capability=%s, feature=%s unavailable", "synchronous MMU", "balloon");
         return NULL;
     }
 
     info = g_malloc0(sizeof(*info));
 
     if (qemu_balloon_status(info) == 0) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "balloon");
         qapi_free_BalloonInfo(info);
         return NULL;
     }
@@ -117,16 +117,16 @@ BalloonInfo *qmp_query_balloon(Error **errp)
 void qmp_balloon(int64_t value, Error **errp)
 {
     if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+        error_set(errp, /* QERR_KVM_MISSING_CAP */ 38, "Using KVM without capability=%s, feature=%s unavailable", "synchronous MMU", "balloon");
         return;
     }
 
     if (value <= 0) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size");
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "target", "a size");
         return;
     }
     
     if (qemu_balloon(value) == 0) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "balloon");
     }
 }
diff --git a/block.c b/block.c
index ce7eb8f..c8d418a 100644
--- a/block.c
+++ b/block.c
@@ -4034,7 +4034,7 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
     BlockJob *job;
 
     if (bs->job || bdrv_in_use(bs)) {
-        error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
+        error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", bdrv_get_device_name(bs));
         return NULL;
     }
     bdrv_set_in_use(bs, 1);
@@ -4079,7 +4079,7 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
     Error *local_err = NULL;
 
     if (!job->job_type->set_speed) {
-        error_set(errp, QERR_NOT_SUPPORTED);
+        error_set(errp, /* QERR_NOT_SUPPORTED */ 44, "Not supported");
         return;
     }
     job->job_type->set_speed(job, speed, &local_err);
diff --git a/block/qcow.c b/block/qcow.c
index e820099..0b1f87c 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -180,9 +180,7 @@ static int qcow_open(BlockDriverState *bs, int flags)
     }
 
     /* Disable migration when qcow images are used */
-    error_set(&s->migration_blocker,
-              QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "qcow", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "qcow", bs->device_name, "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     qemu_co_mutex_init(&s->lock);
diff --git a/block/stream.c b/block/stream.c
index 37c4652..8ddaa59 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -168,7 +168,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)
     StreamBlockJob *s = container_of(job, StreamBlockJob, common);
 
     if (speed < 0) {
-        error_set(errp, QERR_INVALID_PARAMETER, "speed");
+        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "speed");
         return;
     }
     ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
diff --git a/block/vdi.c b/block/vdi.c
index 57325d6..dadde29 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -440,9 +440,7 @@ static int vdi_open(BlockDriverState *bs, int flags)
     }
 
     /* Disable migration when vdi images are used */
-    error_set(&s->migration_blocker,
-              QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "vdi", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vdi", bs->device_name, "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
diff --git a/block/vmdk.c b/block/vmdk.c
index 18e9b4c..49ee6cd 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -663,9 +663,7 @@ static int vmdk_open(BlockDriverState *bs, int flags)
     qemu_co_mutex_init(&s->lock);
 
     /* Disable migration when VMDK images are used */
-    error_set(&s->migration_blocker,
-              QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "vmdk", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vmdk", bs->device_name, "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
diff --git a/block/vpc.c b/block/vpc.c
index 5cd13d1..662e3f8 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -255,9 +255,7 @@ static int vpc_open(BlockDriverState *bs, int flags)
     qemu_co_mutex_init(&s->lock);
 
     /* Disable migration when VHD images are used */
-    error_set(&s->migration_blocker,
-              QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-              "vpc", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vpc", bs->device_name, "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
diff --git a/block/vvfat.c b/block/vvfat.c
index 7b1dcee..cf9e9eb 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1091,9 +1091,7 @@ DLOG(if (stderr == NULL) {
 
     /* Disable migration when vvfat is used rw */
     if (s->qcow) {
-        error_set(&s->migration_blocker,
-                  QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
-                  "vvfat (rw)", bs->device_name, "live migration");
+        error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vvfat (rw)", bs->device_name, "live migration");
         migrate_add_blocker(s->migration_blocker);
     }
 
diff --git a/blockdev.c b/blockdev.c
index 6060c88..e737d2f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -739,29 +739,29 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
 
         drv = bdrv_find_format(format);
         if (!drv) {
-            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
+            error_set(errp, /* QERR_INVALID_BLOCK_FORMAT */ 28, "Invalid block format 'name=%s'", format);
             goto delete_and_fail;
         }
 
         states->old_bs = bdrv_find(device);
         if (!states->old_bs) {
-            error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+            error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
             goto delete_and_fail;
         }
 
         if (!bdrv_is_inserted(states->old_bs)) {
-            error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
+            error_set(errp, /* QERR_DEVICE_HAS_NO_MEDIUM */ 12, "Device 'device=%s' has no medium", device);
             goto delete_and_fail;
         }
 
         if (bdrv_in_use(states->old_bs)) {
-            error_set(errp, QERR_DEVICE_IN_USE, device);
+            error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
             goto delete_and_fail;
         }
 
         if (!bdrv_is_read_only(states->old_bs)) {
             if (bdrv_flush(states->old_bs)) {
-                error_set(errp, QERR_IO_ERROR);
+                error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
                 goto delete_and_fail;
             }
         }
@@ -770,7 +770,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
 
         proto_drv = bdrv_find_protocol(new_image_file);
         if (!proto_drv) {
-            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
+            error_set(errp, /* QERR_INVALID_BLOCK_FORMAT */ 28, "Invalid block format 'name=%s'", format);
             goto delete_and_fail;
         }
 
@@ -781,7 +781,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
                                   states->old_bs->drv->format_name,
                                   NULL, -1, flags);
             if (ret) {
-                error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+                error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", new_image_file);
                 goto delete_and_fail;
             }
         }
@@ -791,7 +791,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
         ret = bdrv_open(states->new_bs, new_image_file,
                         flags | BDRV_O_NO_BACKING, drv);
         if (ret != 0) {
-            error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+            error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", new_image_file);
             goto delete_and_fail;
         }
     }
@@ -828,18 +828,18 @@ exit:
 static void eject_device(BlockDriverState *bs, int force, Error **errp)
 {
     if (bdrv_in_use(bs)) {
-        error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
+        error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", bdrv_get_device_name(bs));
         return;
     }
     if (!bdrv_dev_has_removable_media(bs)) {
-        error_set(errp, QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
+        error_set(errp, /* QERR_DEVICE_NOT_REMOVABLE */ 23, "Device 'device=%s' is not removable", bdrv_get_device_name(bs));
         return;
     }
 
     if (bdrv_dev_is_medium_locked(bs) && !bdrv_dev_is_tray_open(bs)) {
         bdrv_dev_eject_request(bs, force);
         if (!force) {
-            error_set(errp, QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
+            error_set(errp, /* QERR_DEVICE_LOCKED */ 16, "Device 'device=%s' is locked", bdrv_get_device_name(bs));
             return;
         }
     }
@@ -853,7 +853,7 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
         return;
     }
 
@@ -867,16 +867,16 @@ void qmp_block_passwd(const char *device, const char *password, Error **errp)
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
         return;
     }
 
     err = bdrv_set_key(bs, password);
     if (err == -EINVAL) {
-        error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
+        error_set(errp, /* QERR_DEVICE_NOT_ENCRYPTED */ 21, "Device 'device=%s' is not encrypted", bdrv_get_device_name(bs));
         return;
     } else if (err < 0) {
-        error_set(errp, QERR_INVALID_PASSWORD);
+        error_set(errp, /* QERR_INVALID_PASSWORD */ 34, "Password incorrect");
         return;
     }
 }
@@ -886,21 +886,20 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
                                     const char *password, Error **errp)
 {
     if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
         return;
     }
 
     if (bdrv_key_required(bs)) {
         if (password) {
             if (bdrv_set_key(bs, password) < 0) {
-                error_set(errp, QERR_INVALID_PASSWORD);
+                error_set(errp, /* QERR_INVALID_PASSWORD */ 34, "Password incorrect");
             }
         } else {
-            error_set(errp, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs),
-                      bdrv_get_encrypted_filename(bs));
+            error_set(errp, /* QERR_DEVICE_ENCRYPTED */ 10, "Device 'device=%s' is encrypted (filename=filename=%s)", bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs));
         }
     } else if (password) {
-        error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
+        error_set(errp, /* QERR_DEVICE_NOT_ENCRYPTED */ 21, "Device 'device=%s' is not encrypted", bdrv_get_device_name(bs));
     }
 }
 
@@ -914,14 +913,14 @@ void qmp_change_blockdev(const char *device, const char *filename,
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
         return;
     }
 
     if (format) {
         drv = bdrv_find_whitelisted_format(format);
         if (!drv) {
-            error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
+            error_set(errp, /* QERR_INVALID_BLOCK_FORMAT */ 28, "Invalid block format 'name=%s'", format);
             return;
         }
     }
@@ -948,7 +947,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
         return;
     }
 
@@ -960,7 +959,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
     io_limits.iops[BLOCK_IO_LIMIT_WRITE]= iops_wr;
 
     if (!do_check_io_limits(&io_limits)) {
-        error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
+        error_set(errp, /* QERR_INVALID_PARAMETER_COMBINATION */ 31, "Invalid parameter combination");
         return;
     }
 
@@ -1018,12 +1017,12 @@ void qmp_block_resize(const char *device, int64_t size, Error **errp)
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
         return;
     }
 
     if (size < 0) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size");
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "size", "a >0 size");
         return;
     }
 
@@ -1031,19 +1030,19 @@ void qmp_block_resize(const char *device, int64_t size, Error **errp)
     case 0:
         break;
     case -ENOMEDIUM:
-        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
+        error_set(errp, /* QERR_DEVICE_HAS_NO_MEDIUM */ 12, "Device 'device=%s' has no medium", device);
         break;
     case -ENOTSUP:
-        error_set(errp, QERR_UNSUPPORTED);
+        error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
         break;
     case -EACCES:
-        error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
+        error_set(errp, /* QERR_DEVICE_IS_READ_ONLY */ 15, "Device 'device=%s' is read only", device);
         break;
     case -EBUSY:
-        error_set(errp, QERR_DEVICE_IN_USE, device);
+        error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
         break;
     default:
-        error_set(errp, QERR_UNDEFINED_ERROR);
+        error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
         break;
     }
 }
@@ -1096,14 +1095,14 @@ void qmp_block_stream(const char *device, bool has_base,
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
         return;
     }
 
     if (base) {
         base_bs = bdrv_find_backing_image(bs, base);
         if (base_bs == NULL) {
-            error_set(errp, QERR_BASE_NOT_FOUND, base);
+            error_set(errp, /* QERR_BASE_NOT_FOUND */ 3, "Base 'base=%s' not found", base);
             return;
         }
     }
@@ -1139,7 +1138,7 @@ void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp)
     BlockJob *job = find_block_job(device);
 
     if (!job) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, device);
+        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", device);
         return;
     }
 
@@ -1151,7 +1150,7 @@ void qmp_block_job_cancel(const char *device, Error **errp)
     BlockJob *job = find_block_job(device);
 
     if (!job) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, device);
+        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", device);
         return;
     }
 
diff --git a/cpus.c b/cpus.c
index b182b3d..f72c117 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1246,14 +1246,13 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
     }
 
     if (env == NULL) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
-                  "a CPU number");
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "cpu-index", "a CPU number");
         return;
     }
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
         return;
     }
 
@@ -1263,7 +1262,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
             l = size;
         cpu_memory_rw_debug(env, addr, buf, l, 0);
         if (fwrite(buf, 1, l, f) != l) {
-            error_set(errp, QERR_IO_ERROR);
+            error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
             goto exit;
         }
         addr += l;
@@ -1283,7 +1282,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
         return;
     }
 
@@ -1293,7 +1292,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
             l = size;
         cpu_physical_memory_rw(addr, buf, l, 0);
         if (fwrite(buf, 1, l, f) != l) {
-            error_set(errp, QERR_IO_ERROR);
+            error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
             goto exit;
         }
         addr += l;
@@ -1317,6 +1316,6 @@ void qmp_inject_nmi(Error **errp)
         }
     }
 #else
-    error_set(errp, QERR_UNSUPPORTED);
+    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 #endif
 }
diff --git a/dump-stub.c b/dump-stub.c
index 56d4564..537c947 100644
--- a/dump-stub.c
+++ b/dump-stub.c
@@ -21,7 +21,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
                            int64_t begin, bool has_length, int64_t length,
                            Error **errp)
 {
-    error_set(errp, QERR_UNSUPPORTED);
+    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 }
 
 int cpu_write_elf64_note(write_core_dump_function f,
diff --git a/dump.c b/dump.c
index 2bf8d8d..7cc27f9 100644
--- a/dump.c
+++ b/dump.c
@@ -721,7 +721,7 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
     s->length = length;
     s->start = get_start_block(s);
     if (s->start == -1) {
-        error_set(errp, QERR_INVALID_PARAMETER, "begin");
+        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "begin");
         goto cleanup;
     }
 
@@ -741,14 +741,14 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
 
     ret = cpu_get_dump_info(&s->dump_info);
     if (ret < 0) {
-        error_set(errp, QERR_UNSUPPORTED);
+        error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
         goto cleanup;
     }
 
     s->note_size = cpu_get_note_size(s->dump_info.d_class,
                                      s->dump_info.d_machine, nr_cpus);
     if (ret < 0) {
-        error_set(errp, QERR_UNSUPPORTED);
+        error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
         goto cleanup;
     }
 
@@ -826,11 +826,11 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     int ret;
 
     if (has_begin && !has_length) {
-        error_set(errp, QERR_MISSING_PARAMETER, "length");
+        error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "length");
         return;
     }
     if (!has_begin && has_length) {
-        error_set(errp, QERR_MISSING_PARAMETER, "begin");
+        error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "begin");
         return;
     }
 
@@ -838,7 +838,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     if (strstart(file, "fd:", &p)) {
         fd = monitor_get_fd(cur_mon, p);
         if (fd == -1) {
-            error_set(errp, QERR_FD_NOT_FOUND, p);
+            error_set(errp, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", p);
             return;
         }
     }
@@ -847,13 +847,13 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     if  (strstart(file, "file:", &p)) {
         fd = qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR);
         if (fd < 0) {
-            error_set(errp, QERR_OPEN_FILE_FAILED, p);
+            error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", p);
             return;
         }
     }
 
     if (fd == -1) {
-        error_set(errp, QERR_INVALID_PARAMETER, "protocol");
+        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
         return;
     }
 
@@ -866,7 +866,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     }
 
     if (create_vmcore(s) < 0 && !error_is_set(s->errp)) {
-        error_set(errp, QERR_IO_ERROR);
+        error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
     }
 
     g_free(s);
diff --git a/error.c b/error.c
index acb10a2..a410cc2 100644
--- a/error.c
+++ b/error.c
@@ -21,12 +21,14 @@ struct Error
 {
     QDict *obj;
     char *msg;
+    int err_class;
 };
 
-void error_set(Error **errp, const char *fmt, ...)
+void error_set(Error **errp, int err_class, const char *fmt, ...)
 {
     Error *err;
     va_list ap;
+    char msg[2048];
 
     if (errp == NULL) {
         return;
@@ -35,9 +37,12 @@ void error_set(Error **errp, const char *fmt, ...)
     err = g_malloc0(sizeof(*err));
 
     va_start(ap, fmt);
-    err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap));
+    vsnprintf(msg, sizeof(msg), fmt, ap);
     va_end(ap);
-    err->msg = qerror_format(fmt, err->obj);
+    err->msg = g_strdup(msg);
+
+    err->obj = build_error_dict(err_class, err->msg);
+    err->err_class = err_class;
 
     *errp = err;
 }
@@ -48,6 +53,7 @@ Error *error_copy(const Error *err)
 
     err_new = g_malloc0(sizeof(*err));
     err_new->msg = g_strdup(err->msg);
+    err_new->err_class = err->err_class;
     err_new->obj = err->obj;
     QINCREF(err_new->obj);
 
diff --git a/error.h b/error.h
index 45ff6c1..de98e48 100644
--- a/error.h
+++ b/error.h
@@ -26,7 +26,7 @@ typedef struct Error Error;
  * Currently, qerror.h defines these error formats.  This function is not
  * meant to be used outside of QEMU.
  */
-void error_set(Error **err, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
+void error_set(Error **err, int err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
 
 /**
  * Returns true if an indirect pointer to an error is pointing to a valid
diff --git a/hmp.c b/hmp.c
index 6b72a64..ceeb8da 100644
--- a/hmp.c
+++ b/hmp.c
@@ -707,7 +707,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
     if (!filename) {
         /* In the future, if 'snapshot-file' is not specified, the snapshot
            will be taken internally. Today it's actually required. */
-        error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
+        error_set(&errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "snapshot-file");
         hmp_handle_error(mon, &errp);
         return;
     }
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f4a7026..8080582 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -985,8 +985,7 @@ static void v9fs_attach(void *opaque)
                              qid.type, qid.version, qid.path);
     s->root_fid = fid;
     /* disable migration */
-    error_set(&s->migration_blocker, QERR_VIRTFS_FEATURE_BLOCKS_MIGRATION,
-              s->ctx.fs_root ? s->ctx.fs_root : "NULL", s->tag);
+    error_set(&s->migration_blocker, /* QERR_VIRTFS_FEATURE_BLOCKS_MIGRATION */ 69, "Migration is disabled when VirtFS export path 'path=%s' is mounted in the guest using mount_tag 'tag=%s'", s->ctx.fs_root ? s->ctx.fs_root : "NULL", s->tag);
     migrate_add_blocker(s->migration_blocker);
 out:
     put_fid(pdu, fidp);
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index bba21c5..f95cd60 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -681,7 +681,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     if (s->role_val == IVSHMEM_PEER) {
-        error_set(&s->migration_blocker, QERR_DEVICE_FEATURE_BLOCKS_MIGRATION, "ivshmem", "peer mode");
+        error_set(&s->migration_blocker, /* QERR_DEVICE_FEATURE_BLOCKS_MIGRATION */ 11, "Migration is disabled when using feature 'feature=%s' in device 'device=%s'", "ivshmem", "peer mode");
         migrate_add_blocker(s->migration_blocker);
     }
 
diff --git a/hw/pci-stub.c b/hw/pci-stub.c
index e083191..448c21e 100644
--- a/hw/pci-stub.c
+++ b/hw/pci-stub.c
@@ -25,7 +25,7 @@
 
 PciInfoList *qmp_query_pci(Error **errp)
 {
-    error_set(errp, QERR_UNSUPPORTED);
+    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return NULL;
 }
 
diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
index b711b6b..c002ecd 100644
--- a/hw/qdev-addr.c
+++ b/hw/qdev-addr.c
@@ -40,7 +40,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     int64_t value;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -52,9 +52,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     if ((uint64_t)value <= (uint64_t) ~(target_phys_addr_t)0) {
         *ptr = value;
     } else {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                  dev->id?:"", name, value, (uint64_t) 0,
-                  (uint64_t) ~(target_phys_addr_t)0);
+        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", dev->id?:"", name, value, (uint64_t) 0, (uint64_t) ~(target_phys_addr_t)0);
     }
 }
 
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index db2ed77..6909a6d 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -600,7 +600,7 @@ void qmp_device_del(const char *id, Error **errp)
 
     dev = qdev_find_recursive(sysbus_get_default(), id);
     if (NULL == dev) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, id);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", id);
         return;
     }
 
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 7677cfd..a6a17d7 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -35,7 +35,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
     int ret;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -73,7 +73,7 @@ static void set_enum(Object *obj, Visitor *v, void *opaque,
     int *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -125,7 +125,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
     bool value;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -165,7 +165,7 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
     uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -232,7 +232,7 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
     uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -265,7 +265,7 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
     uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -290,7 +290,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
     int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -363,7 +363,7 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque,
     uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -451,7 +451,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -656,7 +656,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     VLANState *vlan;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -671,8 +671,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     }
     vlan = qemu_find_vlan(id, 1);
     if (!vlan) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE,
-                  name, prop->info->name);
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, prop->info->name);
         return;
     }
     *ptr = vlan;
@@ -726,7 +725,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
     char *str, *p;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -814,7 +813,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -826,8 +825,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
         if (local_err) {
             error_propagate(errp, local_err);
         } else if (value < -1 || value > 255) {
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
-                      "pci_devfn");
+            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "pci_devfn");
         } else {
             *ptr = value;
         }
@@ -884,7 +882,7 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
     const int64_t max = 32768;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -894,15 +892,13 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                  dev->id?:"", name, (int64_t)value, min, max);
+        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", dev->id?:"", name, (int64_t)value, min, max);
         return;
     }
 
     /* We rely on power-of-2 blocksizes for bitmasks */
     if ((value & (value - 1)) != 0) {
-        error_set(errp, QERR_PROPERTY_VALUE_NOT_POWER_OF2,
-                  dev->id?:"", name, (int64_t)value);
+        error_set(errp, /* QERR_PROPERTY_VALUE_NOT_POWER_OF2 */ 51, "Property 'device=%s.property=%s' doesn't take value 'value=%"PRId64"', it's not a power of 2", dev->id?:"", name, (int64_t)value);
         return;
     }
 
@@ -952,7 +948,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
     unsigned int slot = 0, func = 0;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -1059,17 +1055,14 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
 {
     switch (ret) {
     case -EEXIST:
-        error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
-                  object_get_typename(OBJECT(dev)), prop->name, value);
+        error_set(errp, /* QERR_PROPERTY_VALUE_IN_USE */ 49, "Property 'device=%s.property=%s' can't take value 'value=%s', it's in use", object_get_typename(OBJECT(dev)), prop->name, value);
         break;
     default:
     case -EINVAL:
-        error_set(errp, QERR_PROPERTY_VALUE_BAD,
-                  object_get_typename(OBJECT(dev)), prop->name, value);
+        error_set(errp, /* QERR_PROPERTY_VALUE_BAD */ 48, "Property 'device=%s.property=%s' doesn't take value 'value=%s'", object_get_typename(OBJECT(dev)), prop->name, value);
         break;
     case -ENOENT:
-        error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
-                  object_get_typename(OBJECT(dev)), prop->name, value);
+        error_set(errp, /* QERR_PROPERTY_VALUE_NOT_FOUND */ 50, "Property 'device=%s.property=%s' can't find value 'value=%s'", object_get_typename(OBJECT(dev)), prop->name, value);
         break;
     case 0:
         break;
diff --git a/hw/qdev.c b/hw/qdev.c
index af54467..390403c 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -199,7 +199,7 @@ void qdev_unplug(DeviceState *dev, Error **errp)
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
     if (!dev->parent_bus->allow_hotplug) {
-        error_set(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
+        error_set(errp, /* QERR_BUS_NO_HOTPLUG */ 6, "Bus 'bus=%s' does not support hotplugging", dev->parent_bus->name);
         return;
     }
     assert(dc->unplug != NULL);
@@ -207,7 +207,7 @@ void qdev_unplug(DeviceState *dev, Error **errp)
     qdev_hot_removed = true;
 
     if (dc->unplug(dev) < 0) {
-        error_set(errp, QERR_UNDEFINED_ERROR);
+        error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
         return;
     }
 }
@@ -570,7 +570,7 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
     int ret;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
         return;
     }
 
diff --git a/json-parser.c b/json-parser.c
index 849e215..c113064 100644
--- a/json-parser.c
+++ b/json-parser.c
@@ -105,7 +105,7 @@ static void GCC_FMT_ATTR(3, 4) parse_error(JSONParserContext *ctxt,
         error_free(ctxt->err);
         ctxt->err = NULL;
     }
-    error_set(&ctxt->err, QERR_JSON_PARSE_ERROR, message);
+    error_set(&ctxt->err, /* QERR_JSON_PARSE_ERROR */ 36, "JSON parse error, message=%s", message);
 }
 
 /**
diff --git a/migration.c b/migration.c
index 8db1b43..d1788c8 100644
--- a/migration.c
+++ b/migration.c
@@ -412,7 +412,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     params.shared = inc;
 
     if (s->state == MIG_STATE_ACTIVE) {
-        error_set(errp, QERR_MIGRATION_ACTIVE);
+        error_set(errp, /* QERR_MIGRATION_ACTIVE */ 39, "There\'s a migration process in progress");
         return;
     }
 
@@ -438,7 +438,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         ret = fd_start_outgoing_migration(s, p);
 #endif
     } else {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "uri", "a valid migration protocol");
         return;
     }
 
@@ -446,7 +446,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         if (!error_is_set(errp)) {
             DPRINTF("migration failed: %s\n", strerror(-ret));
             /* FIXME: we should return meaningful errors */
-            error_set(errp, QERR_UNDEFINED_ERROR);
+            error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
         }
         return;
     }
diff --git a/monitor.c b/monitor.c
index 0ccca3b..a5ec2c8 100644
--- a/monitor.c
+++ b/monitor.c
@@ -626,8 +626,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
         int ret = monitor_set_cpu(cpu_index);
         if (ret < 0) {
             cur_mon = old_mon;
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
-                      "a CPU number");
+            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "cpu-index", "a CPU number");
             goto out;
         }
     }
@@ -2285,13 +2284,12 @@ void qmp_getfd(const char *fdname, Error **errp)
 
     fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
     if (fd == -1) {
-        error_set(errp, QERR_FD_NOT_SUPPLIED);
+        error_set(errp, /* QERR_FD_NOT_SUPPLIED */ 26, "No file descriptor supplied via SCM_RIGHTS");
         return;
     }
 
     if (qemu_isdigit(fdname[0])) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
-                  "a name not starting with a digit");
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "fdname", "a name not starting with a digit");
         return;
     }
 
@@ -2328,7 +2326,7 @@ void qmp_closefd(const char *fdname, Error **errp)
         return;
     }
 
-    error_set(errp, QERR_FD_NOT_FOUND, fdname);
+    error_set(errp, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", fdname);
 }
 
 static void do_loadvm(Monitor *mon, const QDict *qdict)
diff --git a/net.c b/net.c
index abf0fd0..bf4a7c3 100644
--- a/net.c
+++ b/net.c
@@ -1089,7 +1089,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
 
     type = qemu_opt_get(opts, "type");
     if (!type) {
-        error_set(errp, QERR_MISSING_PARAMETER, "type");
+        error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "type");
         return -1;
     }
 
@@ -1105,21 +1105,20 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
             strcmp(type, "vde") != 0 &&
 #endif
             strcmp(type, "socket") != 0) {
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                      "a netdev backend type");
+            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "type", "a netdev backend type");
             return -1;
         }
 
         if (qemu_opt_get(opts, "vlan")) {
-            error_set(errp, QERR_INVALID_PARAMETER, "vlan");
+            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "vlan");
             return -1;
         }
         if (qemu_opt_get(opts, "name")) {
-            error_set(errp, QERR_INVALID_PARAMETER, "name");
+            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "name");
             return -1;
         }
         if (!qemu_opts_id(opts)) {
-            error_set(errp, QERR_MISSING_PARAMETER, "id");
+            error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "id");
             return -1;
         }
     }
@@ -1154,7 +1153,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
                 ret = net_client_types[i].init(opts, name, vlan);
                 if (ret < 0) {
                     /* TODO push error reporting into init() methods */
-                    error_set(errp, QERR_DEVICE_INIT_FAILED, type);
+                    error_set(errp, /* QERR_DEVICE_INIT_FAILED */ 13, "Device 'device=%s' could not be initialized", type);
                     return -1;
                 }
             }
@@ -1162,8 +1161,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
         }
     }
 
-    error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-              "a network client type");
+    error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "type", "a network client type");
     return -1;
 }
 
@@ -1275,7 +1273,7 @@ void qmp_netdev_del(const char *id, Error **errp)
 
     vc = qemu_find_netdev(id);
     if (!vc) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, id);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", id);
         return;
     }
 
@@ -1338,7 +1336,7 @@ void qmp_set_link(const char *name, bool up, Error **errp)
 done:
 
     if (!vc) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, name);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", name);
         return;
     }
 
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 705eca9..e652039 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -107,8 +107,7 @@ void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < 0 || value > UINT8_MAX) {
-                error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
-                          "uint8_t");
+                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "uint8_t");
                 return;
             }
             *obj = value;
@@ -126,8 +125,7 @@ void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < 0 || value > UINT16_MAX) {
-                error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
-                          "uint16_t");
+                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "uint16_t");
                 return;
             }
             *obj = value;
@@ -145,8 +143,7 @@ void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < 0 || value > UINT32_MAX) {
-                error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
-                          "uint32_t");
+                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "uint32_t");
                 return;
             }
             *obj = value;
@@ -178,8 +175,7 @@ void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < INT8_MIN || value > INT8_MAX) {
-                error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
-                          "int8_t");
+                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "int8_t");
                 return;
             }
             *obj = value;
@@ -197,8 +193,7 @@ void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < INT16_MIN || value > INT16_MAX) {
-                error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
-                          "int16_t");
+                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "int16_t");
                 return;
             }
             *obj = value;
@@ -216,8 +211,7 @@ void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < INT32_MIN || value > INT32_MAX) {
-                error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
-                          "int32_t");
+                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "int32_t");
                 return;
             }
             *obj = value;
@@ -268,7 +262,7 @@ void output_type_enum(Visitor *v, int *obj, const char *strings[],
     assert(strings);
     while (strings[i++] != NULL);
     if (value < 0 || value >= i - 1) {
-        error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
+        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", name ? name : "null");
         return;
     }
 
@@ -298,7 +292,7 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],
     }
 
     if (strings[value] == NULL) {
-        error_set(errp, QERR_INVALID_PARAMETER, enum_str);
+        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", enum_str);
         g_free(enum_str);
         return;
     }
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 29d6f30..df2c12e 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -27,8 +27,7 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
     QDict *dict = NULL;
 
     if (qobject_type(request) != QTYPE_QDICT) {
-        error_set(errp, QERR_QMP_BAD_INPUT_OBJECT,
-                  "request is not a dictionary");
+        error_set(errp, /* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "request is not a dictionary");
         return NULL;
     }
 
@@ -41,19 +40,18 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
 
         if (!strcmp(arg_name, "execute")) {
             if (qobject_type(arg_obj) != QTYPE_QSTRING) {
-                error_set(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "execute",
-                          "string");
+                error_set(errp, /* QERR_QMP_BAD_INPUT_OBJECT_MEMBER */ 56, "QMP input object member 'member=%s' expects 'expected=%s'", "execute", "string");
                 return NULL;
             }
             has_exec_key = true;
         } else if (strcmp(arg_name, "arguments")) {
-            error_set(errp, QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER, arg_name);
+            error_set(errp, /* QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER */ 57, "QMP input object member 'member=%s' is unexpected", arg_name);
             return NULL;
         }
     }
 
     if (!has_exec_key) {
-        error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "execute");
+        error_set(errp, /* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "execute");
         return NULL;
     }
 
@@ -76,11 +74,11 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)
     command = qdict_get_str(dict, "execute");
     cmd = qmp_find_command(command);
     if (cmd == NULL) {
-        error_set(errp, QERR_COMMAND_NOT_FOUND, command);
+        error_set(errp, /* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", command);
         return NULL;
     }
     if (!cmd->enabled) {
-        error_set(errp, QERR_COMMAND_DISABLED, command);
+        error_set(errp, /* QERR_COMMAND_DISABLED */ 8, "The command name=%s has been disabled for this instance", command);
         return NULL;
     }
 
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index a59d4f6..351a4a6 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -70,7 +70,7 @@ static void qmp_input_push(QmpInputVisitor *qiv, QObject *obj, Error **errp)
     GHashTable *h;
 
     if (qiv->nb_stack >= QIV_STACK_SIZE) {
-        error_set(errp, QERR_BUFFER_OVERRUN);
+        error_set(errp, /* QERR_BUFFER_OVERRUN */ 5, "An internal buffer overran");
         return;
     }
 
@@ -104,7 +104,7 @@ static void qmp_input_pop(QmpInputVisitor *qiv, Error **errp)
             if (g_hash_table_size(top_ht)) {
                 const char *key;
                 g_hash_table_find(top_ht, always_true, &key);
-                error_set(errp, QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER, key);
+                error_set(errp, /* QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER */ 57, "QMP input object member 'member=%s' is unexpected", key);
             }
             g_hash_table_unref(top_ht);
         }
@@ -121,8 +121,7 @@ static void qmp_input_start_struct(Visitor *v, void **obj, const char *kind,
     Error *err = NULL;
 
     if (!qobj || qobject_type(qobj) != QTYPE_QDICT) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "QDict");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "QDict");
         return;
     }
 
@@ -150,8 +149,7 @@ static void qmp_input_start_list(Visitor *v, const char *name, Error **errp)
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QLIST) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "list");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "list");
         return;
     }
 
@@ -202,8 +200,7 @@ static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name,
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QINT) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "integer");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "integer");
         return;
     }
 
@@ -217,8 +214,7 @@ static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name,
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QBOOL) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "boolean");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "boolean");
         return;
     }
 
@@ -232,8 +228,7 @@ static void qmp_input_type_str(Visitor *v, char **obj, const char *name,
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QSTRING) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "string");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "string");
         return;
     }
 
@@ -248,8 +243,7 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name,
 
     if (!qobj || (qobject_type(qobj) != QTYPE_QFLOAT &&
         qobject_type(qobj) != QTYPE_QINT)) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "number");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "number");
         return;
     }
 
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index 497eb9a..d0eba4e 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -33,8 +33,7 @@ static void parse_type_int(Visitor *v, int64_t *obj, const char *name,
         val = strtoll(siv->string, &endp, 0);
     }
     if (!siv->string || errno || endp == siv->string || *endp) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "integer");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "integer");
         return;
     }
 
@@ -61,8 +60,7 @@ static void parse_type_bool(Visitor *v, bool *obj, const char *name,
         }
     }
 
-    error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-              "boolean");
+    error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "boolean");
 }
 
 static void parse_type_str(Visitor *v, char **obj, const char *name,
@@ -72,8 +70,7 @@ static void parse_type_str(Visitor *v, char **obj, const char *name,
     if (siv->string) {
         *obj = g_strdup(siv->string);
     } else {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "string");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "string");
     }
 }
 
@@ -89,8 +86,7 @@ static void parse_type_number(Visitor *v, double *obj, const char *name,
         val = strtod(siv->string, &endp);
     }
     if (!siv->string || errno || endp == siv->string || *endp) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
-                  "number");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "number");
         return;
     }
 
diff --git a/qemu-config.c b/qemu-config.c
index 5c3296b..09c3be4 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -654,7 +654,7 @@ static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
             break;
     }
     if (lists[i] == NULL) {
-        error_set(errp, QERR_INVALID_OPTION_GROUP, group);
+        error_set(errp, /* QERR_INVALID_OPTION_GROUP */ 29, "There is no option group 'group=%s'", group);
     }
     return lists[i];
 }
diff --git a/qemu-ga.c b/qemu-ga.c
index 8199da7..d1e2b0c 100644
--- a/qemu-ga.c
+++ b/qemu-ga.c
@@ -511,7 +511,7 @@ static void process_event(JSONMessageParser *parser, QList *tokens)
         qdict = qdict_new();
         if (!err) {
             g_warning("failed to parse event: unknown error");
-            error_set(&err, QERR_JSON_PARSING);
+            error_set(&err, /* QERR_JSON_PARSING */ 37, "Invalid JSON syntax");
         } else {
             g_warning("failed to parse event: %s", error_get_pretty(err));
         }
@@ -531,7 +531,7 @@ static void process_event(JSONMessageParser *parser, QList *tokens)
             QDECREF(qdict);
             qdict = qdict_new();
             g_warning("unrecognized payload format");
-            error_set(&err, QERR_UNSUPPORTED);
+            error_set(&err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
             qdict_put_obj(qdict, "error", error_get_qobject(err));
             error_free(err);
         }
diff --git a/qemu-option.c b/qemu-option.c
index a351ed9..df24142 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -178,7 +178,7 @@ static void parse_option_bool(const char *name, const char *value, bool *ret,
         } else if (!strcmp(value, "off")) {
             *ret = 0;
         } else {
-            error_set(errp,QERR_INVALID_PARAMETER_VALUE, name, "'on' or 'off'");
+            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "'on' or 'off'");
         }
     } else {
         *ret = 1;
@@ -194,12 +194,12 @@ static void parse_option_number(const char *name, const char *value,
     if (value != NULL) {
         number = strtoull(value, &postfix, 0);
         if (*postfix != '\0') {
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
+            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a number");
             return;
         }
         *ret = number;
     } else {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a number");
     }
 }
 
@@ -230,13 +230,13 @@ static void parse_option_size(const char *name, const char *value,
             *ret = (uint64_t) sizef;
             break;
         default:
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
+            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a size");
             error_printf_unless_qmp("You may use k, M, G or T suffixes for "
                     "kilobytes, megabytes, gigabytes and terabytes.\n");
             return;
         }
     } else {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
+        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a size");
     }
 }
 
@@ -629,7 +629,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         if (i == 0) {
             /* empty list -> allow any */;
         } else {
-            error_set(errp, QERR_INVALID_PARAMETER, name);
+            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", name);
             return;
         }
     }
@@ -761,14 +761,14 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
 
     if (id) {
         if (!id_wellformed(id)) {
-            error_set(errp,QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "id", "an identifier");
             error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
             return NULL;
         }
         opts = qemu_opts_find(list, id);
         if (opts != NULL) {
             if (fail_if_exists && !list->merge_lists) {
-                error_set(errp, QERR_DUPLICATE_ID, id, list->name);
+                error_set(errp, /* QERR_DUPLICATE_ID */ 24, "Duplicate ID 'id=%s' for object=%s", id, list->name);
                 return NULL;
             } else {
                 return opts;
@@ -1089,7 +1089,7 @@ void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp)
             }
         }
         if (desc[i].name == NULL) {
-            error_set(errp, QERR_INVALID_PARAMETER, opt->name);
+            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", opt->name);
             return;
         }
 
diff --git a/qemu-sockets.c b/qemu-sockets.c
index 20def3e..1051740 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -120,7 +120,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
     if ((qemu_opt_get(opts, "host") == NULL) ||
         (qemu_opt_get(opts, "port") == NULL)) {
         fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
-        error_set(errp, QERR_SOCK_CREATE_FAILED);
+        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
         return -1;
     }
     pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
@@ -139,7 +139,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
     if (rc != 0) {
         fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
                 gai_strerror(rc));
-        error_set(errp, QERR_SOCK_CREATE_FAILED);
+        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
         return -1;
     }
 
@@ -153,7 +153,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
             fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
                     inet_strfamily(e->ai_family), strerror(errno));
             if (!e->ai_next) {
-                error_set(errp, QERR_SOCK_CREATE_FAILED);
+                error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
             }
             continue;
         }
@@ -179,7 +179,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
                         inet_strfamily(e->ai_family), uaddr, inet_getport(e),
                         strerror(errno));
                 if (!e->ai_next) {
-                    error_set(errp, QERR_SOCK_BIND_FAILED);
+                    error_set(errp, /* QERR_SOCK_BIND_FAILED */ 60, "Failed to bind socket");
                 }
             }
         }
@@ -191,7 +191,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
 
 listen:
     if (listen(slisten,1) != 0) {
-        error_set(errp, QERR_SOCK_LISTEN_FAILED);
+        error_set(errp, /* QERR_SOCK_LISTEN_FAILED */ 64, "Failed to set socket to listening mode");
         perror("listen");
         closesocket(slisten);
         freeaddrinfo(res);
@@ -226,7 +226,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
     block = qemu_opt_get_bool(opts, "block", 0);
     if (addr == NULL || port == NULL) {
         fprintf(stderr, "inet_connect: host and/or port not specified\n");
-        error_set(errp, QERR_SOCK_CREATE_FAILED);
+        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
         return -1;
     }
 
@@ -239,7 +239,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
     if (0 != (rc = getaddrinfo(addr, port, &ai, &res))) {
         fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
                 gai_strerror(rc));
-        error_set(errp, QERR_SOCK_CREATE_FAILED);
+        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
 	return -1;
     }
 
@@ -274,7 +274,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
   #else
         if (!block && (rc == -EINPROGRESS)) {
   #endif
-            error_set(errp, QERR_SOCK_CONNECT_INPROGRESS);
+            error_set(errp, /* QERR_SOCK_CONNECT_INPROGRESS */ 62, "Connection can not be completed immediately");
         } else if (rc < 0) {
             if (NULL == e->ai_next)
                 fprintf(stderr, "%s: connect(%s,%s,%s,%s): %s\n", __FUNCTION__,
@@ -287,7 +287,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
         freeaddrinfo(res);
         return sock;
     }
-    error_set(errp, QERR_SOCK_CONNECT_FAILED);
+    error_set(errp, /* QERR_SOCK_CONNECT_FAILED */ 61, "Failed to connect to socket");
     freeaddrinfo(res);
     return -1;
 }
@@ -479,7 +479,7 @@ int inet_listen(const char *str, char *ostr, int olen,
             }
         }
     } else {
-        error_set(errp, QERR_SOCK_CREATE_FAILED);
+        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
     }
     qemu_opts_del(opts);
     return sock;
@@ -497,7 +497,7 @@ int inet_connect(const char *str, bool block, Error **errp)
         }
         sock = inet_connect_opts(opts, errp);
     } else {
-        error_set(errp, QERR_SOCK_CREATE_FAILED);
+        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
     }
     qemu_opts_del(opts);
     return sock;
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index ce90421..e881f3e 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -60,8 +60,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
     } else if (strcmp(mode, "reboot") == 0) {
         shutdown_flag = "-r";
     } else {
-        error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode",
-                  "halt|powerdown|reboot");
+        error_set(err, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "mode", "halt|powerdown|reboot");
         return;
     }
 
@@ -88,7 +87,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
     }
 
 exit_err:
-    error_set(err, QERR_UNDEFINED_ERROR);
+    error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
 }
 
 typedef struct GuestFileHandle {
@@ -137,7 +136,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     slog("guest-file-open called, filepath: %s, mode: %s", path, mode);
     fh = fopen(path, mode);
     if (!fh) {
-        error_set(err, QERR_OPEN_FILE_FAILED, path);
+        error_set(err, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", path);
         return -1;
     }
 
@@ -148,7 +147,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     ret = fcntl(fd, F_GETFL);
     ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
     if (ret == -1) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fcntl() failed");
+        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fcntl() failed");
         fclose(fh);
         return -1;
     }
@@ -165,13 +164,13 @@ void qmp_guest_file_close(int64_t handle, Error **err)
 
     slog("guest-file-close called, handle: %ld", handle);
     if (!gfh) {
-        error_set(err, QERR_FD_NOT_FOUND, "handle");
+        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
         return;
     }
 
     ret = fclose(gfh->fh);
     if (ret == -1) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fclose() failed");
+        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fclose() failed");
         return;
     }
 
@@ -189,14 +188,14 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
     size_t read_count;
 
     if (!gfh) {
-        error_set(err, QERR_FD_NOT_FOUND, "handle");
+        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
         return NULL;
     }
 
     if (!has_count) {
         count = QGA_READ_COUNT_DEFAULT;
     } else if (count < 0) {
-        error_set(err, QERR_INVALID_PARAMETER, "count");
+        error_set(err, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "count");
         return NULL;
     }
 
@@ -205,7 +204,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
     read_count = fread(buf, 1, count, fh);
     if (ferror(fh)) {
         slog("guest-file-read failed, handle: %ld", handle);
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fread() failed");
+        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fread() failed");
     } else {
         buf[read_count] = 0;
         read_data = g_malloc0(sizeof(GuestFileRead));
@@ -232,7 +231,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
     FILE *fh;
 
     if (!gfh) {
-        error_set(err, QERR_FD_NOT_FOUND, "handle");
+        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
         return NULL;
     }
 
@@ -243,14 +242,14 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
         count = buf_len;
     } else if (count < 0 || count > buf_len) {
         g_free(buf);
-        error_set(err, QERR_INVALID_PARAMETER, "count");
+        error_set(err, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "count");
         return NULL;
     }
 
     write_count = fwrite(buf, 1, count, fh);
     if (ferror(fh)) {
         slog("guest-file-write failed, handle: %ld", handle);
-        error_set(err, QERR_QGA_COMMAND_FAILED, "fwrite() error");
+        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fwrite() error");
     } else {
         write_data = g_malloc0(sizeof(GuestFileWrite));
         write_data->count = write_count;
@@ -271,14 +270,14 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
     int ret;
 
     if (!gfh) {
-        error_set(err, QERR_FD_NOT_FOUND, "handle");
+        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
         return NULL;
     }
 
     fh = gfh->fh;
     ret = fseek(fh, offset, whence);
     if (ret == -1) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno));
+        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", strerror(errno));
     } else {
         seek_data = g_malloc0(sizeof(GuestFileRead));
         seek_data->position = ftell(fh);
@@ -296,14 +295,14 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
     int ret;
 
     if (!gfh) {
-        error_set(err, QERR_FD_NOT_FOUND, "handle");
+        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
         return;
     }
 
     fh = gfh->fh;
     ret = fflush(fh);
     if (ret == EOF) {
-        error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno));
+        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", strerror(errno));
     }
 }
 
@@ -424,7 +423,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
         if (fd == -1) {
             sprintf(err_msg, "failed to open %s, %s", mount->dirname,
                     strerror(errno));
-            error_set(err, QERR_QGA_COMMAND_FAILED, err_msg);
+            error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
             goto error;
         }
 
@@ -442,7 +441,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
             if (errno != EOPNOTSUPP) {
                 sprintf(err_msg, "failed to freeze %s, %s",
                         mount->dirname, strerror(errno));
-                error_set(err, QERR_QGA_COMMAND_FAILED, err_msg);
+                error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
                 close(fd);
                 goto error;
             }
@@ -474,8 +473,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
     QTAILQ_INIT(&mounts);
     ret = build_fs_mount_list(&mounts);
     if (ret) {
-        error_set(err, QERR_QGA_COMMAND_FAILED,
-                  "failed to enumerate filesystems");
+        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to enumerate filesystems");
         return 0;
     }
 
@@ -560,7 +558,7 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
         if (fd == -1) {
             sprintf(err_msg, "failed to open %s, %s", mount->dirname,
                     strerror(errno));
-            error_set(err, QERR_QGA_COMMAND_FAILED, err_msg);
+            error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
             goto error;
         }
 
@@ -575,7 +573,7 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
             if (errno != ENOTTY && errno != EOPNOTSUPP) {
                 sprintf(err_msg, "failed to trim %s, %s",
                         mount->dirname, strerror(errno));
-                error_set(err, QERR_QGA_COMMAND_FAILED, err_msg);
+                error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
                 close(fd);
                 goto error;
             }
@@ -658,7 +656,7 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg,
         case SUSPEND_SUPPORTED:
             return;
         case SUSPEND_NOT_SUPPORTED:
-            error_set(err, QERR_UNSUPPORTED);
+            error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
             return;
         default:
             goto undef_err;
@@ -666,7 +664,7 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg,
     }
 
 undef_err:
-    error_set(err, QERR_UNDEFINED_ERROR);
+    error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
 }
 
 static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,
@@ -727,7 +725,7 @@ static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,
     }
 
 exit_err:
-    error_set(err, QERR_UNDEFINED_ERROR);
+    error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
 }
 
 void qmp_guest_suspend_disk(Error **err)
@@ -785,7 +783,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
     if (getifaddrs(&ifap) < 0) {
         snprintf(err_msg, sizeof(err_msg),
                  "getifaddrs failed: %s", strerror(errno));
-        error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg);
+        error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
         goto error;
     }
 
@@ -823,7 +821,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
             if (sock == -1) {
                 snprintf(err_msg, sizeof(err_msg),
                          "failed to create socket: %s", strerror(errno));
-                error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg);
+                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
                 goto error;
             }
 
@@ -834,7 +832,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
                          "failed to get MAC address of %s: %s",
                          ifa->ifa_name,
                          strerror(errno));
-                error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg);
+                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
                 goto error;
             }
 
@@ -847,7 +845,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
                          (int) mac_addr[4], (int) mac_addr[5]) == -1) {
                 snprintf(err_msg, sizeof(err_msg),
                          "failed to format MAC: %s", strerror(errno));
-                error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg);
+                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
                 goto error;
             }
 
@@ -864,7 +862,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
             if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) {
                 snprintf(err_msg, sizeof(err_msg),
                          "inet_ntop failed : %s", strerror(errno));
-                error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg);
+                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
                 goto error;
             }
 
@@ -886,7 +884,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
             if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) {
                 snprintf(err_msg, sizeof(err_msg),
                          "inet_ntop failed : %s", strerror(errno));
-                error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg);
+                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
                 goto error;
             }
 
@@ -939,22 +937,22 @@ error:
 
 void qmp_guest_suspend_disk(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 }
 
 void qmp_guest_suspend_ram(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 }
 
 void qmp_guest_suspend_hybrid(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 }
 
 GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
 {
-    error_set(errp, QERR_UNSUPPORTED);
+    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return NULL;
 }
 
@@ -964,21 +962,21 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
 
 GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 
     return 0;
 }
 
 int64_t qmp_guest_fsfreeze_freeze(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 
     return 0;
 }
 
 int64_t qmp_guest_fsfreeze_thaw(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 
     return 0;
 }
@@ -987,7 +985,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
 #if !defined(CONFIG_FSTRIM)
 void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 
     return;
 }
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 54bc546..d5bd012 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -36,8 +36,7 @@ static void acquire_privilege(const char *name, Error **err)
         TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token))
     {
         if (!LookupPrivilegeValue(NULL, name, &priv.Privileges[0].Luid)) {
-            error_set(&local_err, QERR_QGA_COMMAND_FAILED,
-                      "no luid for requested privilege");
+            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "no luid for requested privilege");
             goto out;
         }
 
@@ -45,15 +44,13 @@ static void acquire_privilege(const char *name, Error **err)
         priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
         if (!AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0)) {
-            error_set(&local_err, QERR_QGA_COMMAND_FAILED,
-                      "unable to acquire requested privilege");
+            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "unable to acquire requested privilege");
             goto out;
         }
 
         CloseHandle(token);
     } else {
-        error_set(&local_err, QERR_QGA_COMMAND_FAILED,
-                  "failed to open privilege token");
+        error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to open privilege token");
     }
 
 out:
@@ -71,8 +68,7 @@ static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque, Error **e
     }
     HANDLE thread = CreateThread(NULL, 0, func, opaque, 0, NULL);
     if (!thread) {
-        error_set(&local_err, QERR_QGA_COMMAND_FAILED,
-                  "failed to dispatch asynchronous command");
+        error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to dispatch asynchronous command");
         error_propagate(err, local_err);
     }
 }
@@ -90,8 +86,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
     } else if (strcmp(mode, "reboot") == 0) {
         shutdown_flag |= EWX_REBOOT;
     } else {
-        error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode",
-                  "halt|powerdown|reboot");
+        error_set(err, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "mode", "halt|powerdown|reboot");
         return;
     }
 
@@ -104,45 +99,45 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
 
     if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
         slog("guest-shutdown failed: %d", GetLastError());
-        error_set(err, QERR_UNDEFINED_ERROR);
+        error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
     }
 }
 
 int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return 0;
 }
 
 void qmp_guest_file_close(int64_t handle, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 }
 
 GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
                                    int64_t count, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return 0;
 }
 
 GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
                                      bool has_count, int64_t count, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return 0;
 }
 
 GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
                                    int64_t whence, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return 0;
 }
 
 void qmp_guest_file_flush(int64_t handle, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 }
 
 /*
@@ -150,7 +145,7 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
  */
 GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return 0;
 }
 
@@ -160,7 +155,7 @@ GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
  */
 int64_t qmp_guest_fsfreeze_freeze(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return 0;
 }
 
@@ -169,7 +164,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
  */
 int64_t qmp_guest_fsfreeze_thaw(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return 0;
 }
 
@@ -179,7 +174,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
  */
 void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 
     return;
 }
@@ -199,27 +194,23 @@ static void check_suspend_mode(GuestSuspendMode mode, Error **err)
     }
     ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps));
     if (!GetPwrCapabilities(&sys_pwr_caps)) {
-        error_set(&local_err, QERR_QGA_COMMAND_FAILED,
-                  "failed to determine guest suspend capabilities");
+        error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to determine guest suspend capabilities");
         goto out;
     }
 
     switch (mode) {
     case GUEST_SUSPEND_MODE_DISK:
         if (!sys_pwr_caps.SystemS4) {
-            error_set(&local_err, QERR_QGA_COMMAND_FAILED,
-                      "suspend-to-disk not supported by OS");
+            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "suspend-to-disk not supported by OS");
         }
         break;
     case GUEST_SUSPEND_MODE_RAM:
         if (!sys_pwr_caps.SystemS3) {
-            error_set(&local_err, QERR_QGA_COMMAND_FAILED,
-                      "suspend-to-ram not supported by OS");
+            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "suspend-to-ram not supported by OS");
         }
         break;
     default:
-        error_set(&local_err, QERR_INVALID_PARAMETER_VALUE, "mode",
-                  "GuestSuspendMode");
+        error_set(&local_err, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "mode", "GuestSuspendMode");
     }
 
 out:
@@ -271,12 +262,12 @@ void qmp_guest_suspend_ram(Error **err)
 
 void qmp_guest_suspend_hybrid(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
 }
 
 GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
     return NULL;
 }
 
diff --git a/qmp.c b/qmp.c
index fee9fb2..562706f 100644
--- a/qmp.c
+++ b/qmp.c
@@ -108,7 +108,7 @@ void qmp_cpu(int64_t index, Error **errp)
    defined in the VNC subsystem */
 VncInfo *qmp_query_vnc(Error **errp)
 {
-    error_set(errp, QERR_FEATURE_DISABLED, "vnc");
+    error_set(errp, /* QERR_FEATURE_DISABLED */ 27, "The feature 'name=%s' is not enabled", "vnc");
     return NULL;
 };
 #endif
@@ -120,7 +120,7 @@ VncInfo *qmp_query_vnc(Error **errp)
    to be available in the namespace if SPICE is not compiled in */
 SpiceInfo *qmp_query_spice(Error **errp)
 {
-    error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice");
+    error_set(errp, /* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", "query-spice");
     return NULL;
 };
 #endif
@@ -135,8 +135,7 @@ static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
     Error **err = opaque;
 
     if (!error_is_set(err) && bdrv_key_required(bs)) {
-        error_set(err, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs),
-                  bdrv_get_encrypted_filename(bs));
+        error_set(err, /* QERR_DEVICE_ENCRYPTED */ 10, "Device 'device=%s' is encrypted (filename=filename=%s)", bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs));
     }
 }
 
@@ -145,11 +144,11 @@ void qmp_cont(Error **errp)
     Error *local_err = NULL;
 
     if (runstate_check(RUN_STATE_INMIGRATE)) {
-        error_set(errp, QERR_MIGRATION_EXPECTED);
+        error_set(errp, /* QERR_MIGRATION_EXPECTED */ 40, "An incoming migration is expected before this command can be executed");
         return;
     } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
                runstate_check(RUN_STATE_SHUTDOWN)) {
-        error_set(errp, QERR_RESET_REQUIRED);
+        error_set(errp, /* QERR_RESET_REQUIRED */ 58, "Resetting the Virtual Machine is required");
         return;
     } else if (runstate_check(RUN_STATE_SUSPENDED)) {
         return;
@@ -179,7 +178,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
 
     obj = object_resolve_path(path, &ambiguous);
     if (obj == NULL) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, path);
+        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
         return NULL;
     }
 
@@ -208,7 +207,7 @@ int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
 
     obj = object_resolve_path(path, NULL);
     if (!obj) {
-        error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
+        error_set(&local_err, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
         goto out;
     }
 
@@ -233,7 +232,7 @@ int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
 
     obj = object_resolve_path(path, NULL);
     if (!obj) {
-        error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
+        error_set(&local_err, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
         goto out;
     }
 
@@ -264,7 +263,7 @@ void qmp_set_password(const char *protocol, const char *password,
         } else if (strcmp(connected, "keep") == 0) {
             /* nothing */
         } else {
-            error_set(errp, QERR_INVALID_PARAMETER, "connected");
+            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "connected");
             return;
         }
     }
@@ -272,13 +271,13 @@ void qmp_set_password(const char *protocol, const char *password,
     if (strcmp(protocol, "spice") == 0) {
         if (!using_spice) {
             /* correct one? spice isn't a device ,,, */
-            error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+            error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
             return;
         }
         rc = qemu_spice_set_passwd(password, fail_if_connected,
                                    disconnect_if_connected);
         if (rc != 0) {
-            error_set(errp, QERR_SET_PASSWD_FAILED);
+            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
         }
         return;
     }
@@ -286,19 +285,19 @@ void qmp_set_password(const char *protocol, const char *password,
     if (strcmp(protocol, "vnc") == 0) {
         if (fail_if_connected || disconnect_if_connected) {
             /* vnc supports "connected=keep" only */
-            error_set(errp, QERR_INVALID_PARAMETER, "connected");
+            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "connected");
             return;
         }
         /* Note that setting an empty password will not disable login through
          * this interface. */
         rc = vnc_display_password(NULL, password);
         if (rc < 0) {
-            error_set(errp, QERR_SET_PASSWD_FAILED);
+            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
         }
         return;
     }
 
-    error_set(errp, QERR_INVALID_PARAMETER, "protocol");
+    error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
 }
 
 void qmp_expire_password(const char *protocol, const char *whenstr,
@@ -320,12 +319,12 @@ void qmp_expire_password(const char *protocol, const char *whenstr,
     if (strcmp(protocol, "spice") == 0) {
         if (!using_spice) {
             /* correct one? spice isn't a device ,,, */
-            error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+            error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
             return;
         }
         rc = qemu_spice_set_pw_expire(when);
         if (rc != 0) {
-            error_set(errp, QERR_SET_PASSWD_FAILED);
+            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
         }
         return;
     }
@@ -333,26 +332,26 @@ void qmp_expire_password(const char *protocol, const char *whenstr,
     if (strcmp(protocol, "vnc") == 0) {
         rc = vnc_display_pw_expire(NULL, when);
         if (rc != 0) {
-            error_set(errp, QERR_SET_PASSWD_FAILED);
+            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
         }
         return;
     }
 
-    error_set(errp, QERR_INVALID_PARAMETER, "protocol");
+    error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
 }
 
 #ifdef CONFIG_VNC
 void qmp_change_vnc_password(const char *password, Error **errp)
 {
     if (vnc_display_password(NULL, password) < 0) {
-        error_set(errp, QERR_SET_PASSWD_FAILED);
+        error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
     }
 }
 
 static void qmp_change_vnc_listen(const char *target, Error **err)
 {
     if (vnc_display_open(NULL, target) < 0) {
-        error_set(err, QERR_VNC_SERVER_FAILED, target);
+        error_set(err, /* QERR_VNC_SERVER_FAILED */ 70, "Could not start VNC server on target=%s", target);
     }
 }
 
@@ -361,7 +360,7 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
 {
     if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
         if (!has_arg) {
-            error_set(errp, QERR_MISSING_PARAMETER, "password");
+            error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "password");
         } else {
             qmp_change_vnc_password(arg, errp);
         }
@@ -372,12 +371,12 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
 #else
 void qmp_change_vnc_password(const char *password, Error **errp)
 {
-    error_set(errp, QERR_FEATURE_DISABLED, "vnc");
+    error_set(errp, /* QERR_FEATURE_DISABLED */ 27, "The feature 'name=%s' is not enabled", "vnc");
 }
 static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
                            Error **errp)
 {
-    error_set(errp, QERR_FEATURE_DISABLED, "vnc");
+    error_set(errp, /* QERR_FEATURE_DISABLED */ 27, "The feature 'name=%s' is not enabled", "vnc");
 }
 #endif /* !CONFIG_VNC */
 
diff --git a/qom/object.c b/qom/object.c
index 00bb3b0..21b7dba 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -683,7 +683,7 @@ ObjectProperty *object_property_find(Object *obj, const char *name,
         }
     }
 
-    error_set(errp, QERR_PROPERTY_NOT_FOUND, "", name);
+    error_set(errp, /* QERR_PROPERTY_NOT_FOUND */ 47, "Property 'device=%s.property=%s' not found", "", name);
     return NULL;
 }
 
@@ -714,7 +714,7 @@ void object_property_get(Object *obj, Visitor *v, const char *name,
     }
 
     if (!prop->get) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
     } else {
         prop->get(obj, v, prop->opaque, name, errp);
     }
@@ -729,7 +729,7 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
     }
 
     if (!prop->set) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
     } else {
         prop->set(obj, v, prop->opaque, name, errp);
     }
@@ -756,7 +756,7 @@ char *object_property_get_str(Object *obj, const char *name,
     }
     qstring = qobject_to_qstring(ret);
     if (!qstring) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "string");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, "string");
         retval = NULL;
     } else {
         retval = g_strdup(qstring_get_str(qstring));
@@ -782,7 +782,7 @@ Object *object_property_get_link(Object *obj, const char *name,
     if (str && *str) {
         target = object_resolve_path(str, NULL);
         if (!target) {
-            error_set(errp, QERR_DEVICE_NOT_FOUND, str);
+            error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", str);
         }
     }
 
@@ -811,7 +811,7 @@ bool object_property_get_bool(Object *obj, const char *name,
     }
     qbool = qobject_to_qbool(ret);
     if (!qbool) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, "boolean");
         retval = false;
     } else {
         retval = qbool_get_int(qbool);
@@ -842,7 +842,7 @@ int64_t object_property_get_int(Object *obj, const char *name,
     }
     qint = qobject_to_qint(ret);
     if (!qint) {
-        error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, "int");
+        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, "int");
         retval = -1;
     } else {
         retval = qint_get_int(qint);
@@ -979,16 +979,16 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
         target = object_resolve_path_type(path, target_type, &ambiguous);
 
         if (ambiguous) {
-            error_set(errp, QERR_AMBIGUOUS_PATH, path);
+            error_set(errp, /* QERR_AMBIGUOUS_PATH */ 1, "Path 'path=%s' does not uniquely identify an object", path);
         } else if (target) {
             object_ref(target);
             *child = target;
         } else {
             target = object_resolve_path(path, &ambiguous);
             if (target || ambiguous) {
-                error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, target_type);
+                error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, target_type);
             } else {
-                error_set(errp, QERR_DEVICE_NOT_FOUND, path);
+                error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
             }
         }
         g_free(target_type);
diff --git a/savevm.c b/savevm.c
index a15c163..71ae5a7 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1555,7 +1555,7 @@ bool qemu_savevm_state_blocked(Error **errp)
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         if (se->no_migrate) {
-            error_set(errp, QERR_MIGRATION_NOT_SUPPORTED, se->idstr);
+            error_set(errp, /* QERR_MIGRATION_NOT_SUPPORTED */ 41, "State blocked by non-migratable device 'device=%s'", se->idstr);
             return true;
         }
     }
@@ -2182,13 +2182,13 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp)
 
     f = qemu_fopen(filename, "wb");
     if (!f) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
         goto the_end;
     }
     ret = qemu_save_device_state(f);
     qemu_fclose(f);
     if (ret < 0) {
-        error_set(errp, QERR_IO_ERROR);
+        error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
     }
 
  the_end:
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b3bcbac..7da4dfc 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -631,8 +631,7 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                  name ? name : "null", value, min, max);
+        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
         return;
     }
 
@@ -670,8 +669,7 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                  name ? name : "null", value, min, max);
+        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
         return;
     }
 
@@ -706,8 +704,7 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                  name ? name : "null", value, min, max);
+        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
         return;
     }
 
@@ -772,8 +769,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value,
     int i;
 
     if (strlen(value) != 12) {
-        error_set(errp, QERR_PROPERTY_VALUE_BAD, "",
-                  "vendor", value);
+        error_set(errp, /* QERR_PROPERTY_VALUE_BAD */ 48, "Property 'device=%s.property=%s' doesn't take value 'value=%s'", "", "vendor", value);
         return;
     }
 
@@ -848,8 +844,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                  name ? name : "null", value, min, max);
+        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
         return;
     }
 
diff --git a/ui/vnc.c b/ui/vnc.c
index cf1cae2..c448f09 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -373,7 +373,7 @@ VncInfo *qmp_query_vnc(Error **errp)
 
         if (getsockname(vnc_display->lsock, (struct sockaddr *)&sa,
                         &salen) == -1) {
-            error_set(errp, QERR_UNDEFINED_ERROR);
+            error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
             goto out_error;
         }
 
@@ -381,7 +381,7 @@ VncInfo *qmp_query_vnc(Error **errp)
                         host, sizeof(host),
                         serv, sizeof(serv),
                         NI_NUMERICHOST | NI_NUMERICSERV) < 0) {
-            error_set(errp, QERR_UNDEFINED_ERROR);
+            error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
             goto out_error;
         }
 
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (9 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 10/14] error: error_set(): " Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-26 12:54   ` Markus Armbruster
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration Luiz Capitulino
                   ` (4 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

Last commit deprecated it. Also drops the code that used it to generate
error objects.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c               | 95 --------------------------------------------------
 qerror.h               |  6 ----
 scripts/qapi-errors.py | 26 --------------
 3 files changed, 127 deletions(-)

diff --git a/qerror.c b/qerror.c
index 6d61426..1118e2b 100644
--- a/qerror.c
+++ b/qerror.c
@@ -144,101 +144,6 @@ static QError *qerror_from_info(int err_class, const char *fmt, va_list *va)
     return qerr;
 }
 
-static void parse_error(const QErrorStringTable *entry, int c)
-{
-    fprintf(stderr, "expected '%c' in '%s'", c, entry->desc);
-    abort();
-}
-
-static const char *append_field(QDict *error, QString *outstr,
-                                const QErrorStringTable *entry,
-                                const char *start)
-{
-    QObject *obj;
-    QDict *qdict;
-    QString *key_qs;
-    const char *end, *key;
-
-    if (*start != '%')
-        parse_error(entry, '%');
-    start++;
-    if (*start != '(')
-        parse_error(entry, '(');
-    start++;
-
-    end = strchr(start, ')');
-    if (!end)
-        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(error, "data"));
-    obj = qdict_get(qdict, key);
-    if (!obj) {
-        abort();
-    }
-
-    switch (qobject_type(obj)) {
-        case QTYPE_QSTRING:
-            qstring_append(outstr, qdict_get_str(qdict, key));
-            break;
-        case QTYPE_QINT:
-            qstring_append_int(outstr, qdict_get_int(qdict, key));
-            break;
-        default:
-            abort();
-    }
-
-    QDECREF(key_qs);
-    return ++end;
-}
-
-static QString *qerror_format_desc(QDict *error,
-                                   const QErrorStringTable *entry)
-{
-    QString *qstring;
-    const char *p;
-
-    assert(entry != NULL);
-
-    qstring = qstring_new();
-
-    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(error, qstring, entry, p);
-        }
-    }
-
-    return qstring;
-}
-
-char *qerror_format(const char *fmt, QDict *error)
-{
-    const QErrorStringTable *entry = NULL;
-    QString *qstr;
-    char *ret;
-    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;
-        }
-    }
-
-    qstr = qerror_format_desc(error, entry);
-    ret = g_strdup(qstring_get_str(qstr));
-    QDECREF(qstr);
-
-    return ret;
-}
-
 /**
  * qerror_human(): Format QError data into human-readable string.
  */
diff --git a/qerror.h b/qerror.h
index 32e9a22..10d83d8 100644
--- a/qerror.h
+++ b/qerror.h
@@ -19,11 +19,6 @@
 #include "error.h"
 #include <stdarg.h>
 
-typedef struct QErrorStringTable {
-    const char *desc;
-    const char *error_fmt;
-} QErrorStringTable;
-
 typedef struct QError {
     QObject_HEAD;
     QDict *error;
@@ -35,7 +30,6 @@ QString *qerror_human(const QError *qerror);
 void qerror_report(int err_class, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 void qerror_report_err(Error *err);
 void assert_no_error(Error *err);
-char *qerror_format(const char *fmt, QDict *error);
 QDict *build_error_dict(int err_class, const char *msg);
 
 #endif /* QERROR_H */
diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
index 5f8723e..dc656f2 100644
--- a/scripts/qapi-errors.py
+++ b/scripts/qapi-errors.py
@@ -62,29 +62,6 @@ def gen_error_macro(err_domain):
     string += cur
     return 'QERR_' + string.upper()
 
-def gen_error_def_table(exprs):
-    ret = mcgen('''
-static const QErrorStringTable qerror_table[] = {
-''')
-
-    for err in exprs:
-        macro = gen_error_macro(err['error'])
-        desc = err['description']
-        ret += mcgen('''
-        {
-            .error_fmt = %(error_macro)s,
-            .desc      = "%(error_desc)s",
-        },
-''',    
-                    error_macro=macro, error_desc=desc)
-
-    ret += mcgen('''
-    {}
-};
-''')
-
-    return ret
-
 def gen_error_data_obj(data):
     colon = ''
     data_str = ''
@@ -206,9 +183,6 @@ if __name__ == '__main__':
     ret = gen_error_def_prologue(error_header=h_file, prefix=prefix)
     fdef.write(ret)
 
-    ret = gen_error_def_table(exprs)
-    fdef.write(ret)
-
     ret = gen_error_obj_table(exprs)
     fdef.write(ret)
 
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (10 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum Luiz Capitulino
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

The enum is called ErrClass, and is autogenerated.

FIXME: also converts error_is_type() and probably breaks other error
       functions used to query the error object.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 error.c                | 24 ++----------------------
 error.h                |  3 ++-
 scripts/qapi-errors.py | 47 ++++++++++++++++++-----------------------------
 3 files changed, 22 insertions(+), 52 deletions(-)

diff --git a/error.c b/error.c
index a410cc2..529e75f 100644
--- a/error.c
+++ b/error.c
@@ -102,29 +102,9 @@ void error_free(Error *err)
     }
 }
 
-bool error_is_type(Error *err, const char *fmt)
+bool error_is_type(Error *err, ErrClass err_class)
 {
-    const char *error_class;
-    char *ptr;
-    char *end;
-
-    if (!err) {
-        return false;
-    }
-
-    ptr = strstr(fmt, "'class': '");
-    assert(ptr != NULL);
-    ptr += strlen("'class': '");
-
-    end = strchr(ptr, '\'');
-    assert(end != NULL);
-
-    error_class = error_get_field(err, "class");
-    if (strlen(error_class) != end - ptr) {
-        return false;
-    }
-
-    return strncmp(ptr, error_class, end - ptr) == 0;
+    return (err && (err->err_class == err_class));
 }
 
 void error_propagate(Error **dst_err, Error *local_err)
diff --git a/error.h b/error.h
index de98e48..19116ef 100644
--- a/error.h
+++ b/error.h
@@ -13,6 +13,7 @@
 #define ERROR_H
 
 #include "compiler.h"
+#include "qapi-errors.h"
 #include <stdbool.h>
 
 /**
@@ -70,6 +71,6 @@ void error_free(Error *err);
  * Determine if an error is of a speific type (based on the qerror format).
  * Non-QEMU users should get the `class' field to identify the error type.
  */
-bool error_is_type(Error *err, const char *fmt);
+bool error_is_type(Error *err, ErrClass err_class);
 
 #endif
diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
index dc656f2..0f52f43 100644
--- a/scripts/qapi-errors.py
+++ b/scripts/qapi-errors.py
@@ -51,7 +51,7 @@ def gen_error_def_prologue(error_header, prefix=""):
                 prefix=prefix, error_header=error_header)
     return ret
 
-def gen_error_macro(err_domain):
+def gen_error_enum_name(err_domain):
     string = ''
     cur = err_domain[0]
     for nxt in err_domain[1:]:
@@ -82,13 +82,15 @@ static const char *error_object_table[] = {
 ''')
 
     for err in exprs:
+        enum = gen_error_enum_name(err['error'])
         data = gen_error_data_obj({})
         if err.has_key('data'):
             data = gen_error_data_obj(err['data'])
         ret += mcgen('''
-    "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }",
+    [%(error_enum)s] =
+        "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }",
 ''',
-                error_class=err['error'], error_data=data)
+                error_enum=enum, error_class=err['error'], error_data=data)
 
     ret += mcgen('''
     NULL,
@@ -98,35 +100,22 @@ static const char *error_object_table[] = {
 
     return ret;
 
-def gen_error_macro_data_str(data):
-    colon = ''
-    data_str = ''
-    for k, v in data.items():
-        data_str += colon + "'%s': " % k
-        if v == 'str':
-            data_str += "%s"
-        elif v == 'int':
-            data_str += '%"PRId64"'
-        else:
-            sys.exit("unknown data type '%s' for error '%s'" % (v, name))
-        colon = ', '
-    return data_str
+def gen_error_enum(exprs):
+    ret = mcgen('''
+typedef enum ErrClass {
+''')
 
-def gen_error_decl_macros(exprs):
-    ret = ''
     for err in exprs:
-        data = gen_error_macro_data_str({})
-        if err.has_key('data'):
-            data = gen_error_macro_data_str(err['data'])
-        macro = gen_error_macro(err['error'])
-        name = err['error']
-
         ret += mcgen('''
-#define %(error_macro)s \\
-    "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }"
-
+    %(enum)s,
 ''',
-                error_macro=macro, error_class=name, error_data=data)
+        enum=gen_error_enum_name(err['error']))
+
+    ret += mcgen('''
+} ErrClass;
+
+''')
+
     return ret
 
 def maybe_open(really, name, opt):
@@ -172,7 +161,7 @@ if __name__ == '__main__':
     ret = gen_error_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
     fdecl.write(ret)
 
-    ret = gen_error_decl_macros(exprs)
+    ret = gen_error_enum(exprs)
     fdecl.write(ret)
 
     fdecl.write("#endif\n")
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (11 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 14/14] error: change all error_set() " Luiz Capitulino
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 block/cow.c       |  2 +-
 block/qcow.c      |  2 +-
 block/qcow2.c     |  2 +-
 block/qed.c       |  2 +-
 blockdev.c        | 10 +++++-----
 hw/pci.c          |  4 ++--
 hw/qdev-monitor.c | 22 +++++++++++-----------
 hw/usb/bus.c      |  2 +-
 hw/usb/hcd-ehci.c |  4 ++--
 hw/usb/redirect.c |  4 ++--
 monitor.c         | 48 ++++++++++++++++++++++++------------------------
 qemu-option.c     |  2 +-
 12 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 002dcf1..a61708e 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -81,7 +81,7 @@ static int cow_open(BlockDriverState *bs, int flags)
         char version[64];
         snprintf(version, sizeof(version),
                "COW version %d", cow_header.version);
-        qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "cow", version);
+        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s",  bs->device_name,  "cow",  version);
         ret = -ENOTSUP;
         goto fail;
     }
diff --git a/block/qcow.c b/block/qcow.c
index 0b1f87c..b86d547 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -118,7 +118,7 @@ static int qcow_open(BlockDriverState *bs, int flags)
     if (header.version != QCOW_VERSION) {
         char version[64];
         snprintf(version, sizeof(version), "QCOW version %d", header.version);
-        qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "qcow", version);
+        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s",  bs->device_name,  "qcow",  version);
         ret = -ENOTSUP;
         goto fail;
     }
diff --git a/block/qcow2.c b/block/qcow2.c
index a5b46df..7d9c813 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -192,7 +192,7 @@ static void GCC_FMT_ATTR(2, 3) report_unsupported(BlockDriverState *bs,
     vsnprintf(msg, sizeof(msg), fmt, ap);
     va_end(ap);
 
-    qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "qcow2", msg);
+    qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s",  bs->device_name,  "qcow2",  msg);
 }
 
 static void report_unsupported_feature(BlockDriverState *bs,
diff --git a/block/qed.c b/block/qed.c
index fda3dcc..7175a7c 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -397,7 +397,7 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags)
         char buf[64];
         snprintf(buf, sizeof(buf), "%" PRIx64,
             s->header.features & ~QED_FEATURE_MASK);
-        qerror_report(/* QERR_UNKNOWN_BLOCK_FORMAT_FEATURE */ 67, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s", bs->device_name, "QED", buf);
+        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, "'device=%s' uses a format=%s feature which is not supported by this qemu version: feature=%s",  bs->device_name,  "QED",  buf);
         return -ENOTSUP;
     }
     if (!qed_is_cluster_size_valid(s->header.cluster_size)) {
diff --git a/blockdev.c b/blockdev.c
index e737d2f..11c714f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -633,18 +633,18 @@ void do_commit(Monitor *mon, const QDict *qdict)
     if (!strcmp(device, "all")) {
         ret = bdrv_commit_all();
         if (ret == -EBUSY) {
-            qerror_report(/* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
+            qerror_report(QERR_DEVICE_IN_USE, "Device 'device=%s' is in use",  device);
             return;
         }
     } else {
         bs = bdrv_find(device);
         if (!bs) {
-            qerror_report(/* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+            qerror_report(QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
             return;
         }
         ret = bdrv_commit(bs);
         if (ret == -EBUSY) {
-            qerror_report(/* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
+            qerror_report(QERR_DEVICE_IN_USE, "Device 'device=%s' is in use",  device);
             return;
         }
     }
@@ -984,11 +984,11 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 
     bs = bdrv_find(id);
     if (!bs) {
-        qerror_report(/* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", id);
+        qerror_report(QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  id);
         return -1;
     }
     if (bdrv_in_use(bs)) {
-        qerror_report(/* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", id);
+        qerror_report(QERR_DEVICE_IN_USE, "Device 'device=%s' is in use",  id);
         return -1;
     }
 
diff --git a/hw/pci.c b/hw/pci.c
index 1aac667..1970661 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1506,7 +1506,7 @@ static int pci_qdev_init(DeviceState *qdev)
     if (pci_dev == NULL)
         return -1;
     if (qdev->hotplugged && pc->no_hotplug) {
-        qerror_report(/* QERR_DEVICE_NO_HOTPLUG */ 19, "Device 'device=%s' does not support hotplugging", object_get_typename(OBJECT(pci_dev)));
+        qerror_report(QERR_DEVICE_NO_HOTPLUG, "Device 'device=%s' does not support hotplugging",  object_get_typename(OBJECT(pci_dev)));
         do_pci_unregister_device(pci_dev);
         return -1;
     }
@@ -1547,7 +1547,7 @@ static int pci_unplug_device(DeviceState *qdev)
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
 
     if (pc->no_hotplug) {
-        qerror_report(/* QERR_DEVICE_NO_HOTPLUG */ 19, "Device 'device=%s' does not support hotplugging", object_get_typename(OBJECT(dev)));
+        qerror_report(QERR_DEVICE_NO_HOTPLUG, "Device 'device=%s' does not support hotplugging",  object_get_typename(OBJECT(dev)));
         return -1;
     }
     return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 6909a6d..03bb21d 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -326,7 +326,7 @@ static BusState *qbus_find(const char *path)
         }
         bus = qbus_find_recursive(sysbus_get_default(), elem, NULL);
         if (!bus) {
-            qerror_report(/* QERR_BUS_NOT_FOUND */ 7, "Bus 'bus=%s' not found", elem);
+            qerror_report(QERR_BUS_NOT_FOUND, "Bus 'bus=%s' not found",  elem);
             return NULL;
         }
         pos = len;
@@ -349,7 +349,7 @@ static BusState *qbus_find(const char *path)
         pos += len;
         dev = qbus_find_dev(bus, elem);
         if (!dev) {
-            qerror_report(/* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", elem);
+            qerror_report(QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  elem);
             if (!monitor_cur_is_qmp()) {
                 qbus_list_dev(bus);
             }
@@ -365,12 +365,12 @@ static BusState *qbus_find(const char *path)
              * one child bus accept it nevertheless */
             switch (dev->num_child_bus) {
             case 0:
-                qerror_report(/* QERR_DEVICE_NO_BUS */ 18, "Device 'device=%s' has no child bus", elem);
+                qerror_report(QERR_DEVICE_NO_BUS, "Device 'device=%s' has no child bus",  elem);
                 return NULL;
             case 1:
                 return QLIST_FIRST(&dev->child_bus);
             default:
-                qerror_report(/* QERR_DEVICE_MULTIPLE_BUSSES */ 17, "Device 'device=%s' has multiple child busses", elem);
+                qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, "Device 'device=%s' has multiple child busses",  elem);
                 if (!monitor_cur_is_qmp()) {
                     qbus_list_bus(dev);
                 }
@@ -386,7 +386,7 @@ static BusState *qbus_find(const char *path)
         pos += len;
         bus = qbus_find_bus(dev, elem);
         if (!bus) {
-            qerror_report(/* QERR_BUS_NOT_FOUND */ 7, "Bus 'bus=%s' not found", elem);
+            qerror_report(QERR_BUS_NOT_FOUND, "Bus 'bus=%s' not found",  elem);
             if (!monitor_cur_is_qmp()) {
                 qbus_list_bus(dev);
             }
@@ -405,7 +405,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 
     driver = qemu_opt_get(opts, "driver");
     if (!driver) {
-        qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "driver");
+        qerror_report(QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "driver");
         return NULL;
     }
 
@@ -421,7 +421,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
 
     if (!obj) {
-        qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "driver", "device type");
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "driver",  "device type");
         return NULL;
     }
 
@@ -435,18 +435,18 @@ DeviceState *qdev_device_add(QemuOpts *opts)
             return NULL;
         }
         if (strcmp(object_get_typename(OBJECT(bus)), k->bus_type) != 0) {
-            qerror_report(/* QERR_BAD_BUS_FOR_DEVICE */ 2, "Device 'device=%s' can't go on a bad_bus_type=%s bus", driver, object_get_typename(OBJECT(bus)));
+            qerror_report(QERR_BAD_BUS_FOR_DEVICE, "Device 'device=%s' can't go on a bad_bus_type=%s bus",  driver,  object_get_typename(OBJECT(bus)));
             return NULL;
         }
     } else {
         bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type);
         if (!bus) {
-            qerror_report(/* QERR_NO_BUS_FOR_DEVICE */ 43, "No 'bus=%s' bus found for device 'device=%s'", driver, k->bus_type);
+            qerror_report(QERR_NO_BUS_FOR_DEVICE, "No 'bus=%s' bus found for device 'device=%s'",  driver,  k->bus_type);
             return NULL;
         }
     }
     if (qdev_hotplug && !bus->allow_hotplug) {
-        qerror_report(/* QERR_BUS_NO_HOTPLUG */ 6, "Bus 'bus=%s' does not support hotplugging", bus->name);
+        qerror_report(QERR_BUS_NO_HOTPLUG, "Bus 'bus=%s' does not support hotplugging",  bus->name);
         return NULL;
     }
 
@@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         g_free(name);
     }        
     if (qdev_init(qdev) < 0) {
-        qerror_report(/* QERR_DEVICE_INIT_FAILED */ 13, "Device 'device=%s' could not be initialized", driver);
+        qerror_report(QERR_DEVICE_INIT_FAILED, "Device 'device=%s' could not be initialized",  driver);
         return NULL;
     }
     qdev->opts = opts;
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 28901cb..977d4b2 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -303,7 +303,7 @@ int usb_register_companion(const char *masterbus, USBPort *ports[],
     }
 
     if (!bus || !bus->ops->register_companion) {
-        qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "masterbus", "an USB masterbus");
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "masterbus",  "an USB masterbus");
         if (bus) {
             error_printf_unless_qmp(
                 "USB bus '%s' does not allow companion controllers\n",
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 2d42945..a58a36e 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -933,7 +933,7 @@ static int ehci_register_companion(USBBus *bus, USBPort *ports[],
     uint32_t i;
 
     if (firstport + portcount > NB_PORTS) {
-        qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "firstport", "firstport on masterbus");
+        qerror_report(QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "firstport",  "firstport on masterbus");
         error_printf_unless_qmp(
             "firstport value of %u makes companion take ports %u - %u, which "
             "is outside of the valid range of 0 - %u\n", firstport, firstport,
@@ -943,7 +943,7 @@ static int ehci_register_companion(USBBus *bus, USBPort *ports[],
 
     for (i = 0; i < portcount; i++) {
         if (s->companion_ports[firstport + i]) {
-            qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "masterbus", "an USB masterbus");
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "masterbus",  "an USB masterbus");
             error_printf_unless_qmp(
                 "port %u on masterbus %s already has a companion assigned\n",
                 firstport + i, bus->qbus.name);
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index d43dae2..7ca5444 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -902,7 +902,7 @@ static int usbredir_initfn(USBDevice *udev)
     int i;
 
     if (dev->cs == NULL) {
-        qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "chardev");
+        qerror_report(QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "chardev");
         return -1;
     }
 
@@ -911,7 +911,7 @@ static int usbredir_initfn(USBDevice *udev)
                                            &dev->filter_rules,
                                            &dev->filter_rules_count);
         if (i) {
-            qerror_report(/* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "filter", "a usb device filter string");
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "filter",  "a usb device filter string");
             return -1;
         }
     }
diff --git a/monitor.c b/monitor.c
index a5ec2c8..62d56a4 100644
--- a/monitor.c
+++ b/monitor.c
@@ -227,7 +227,7 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
                           void *opaque)
 {
     if (monitor_ctrl_mode(mon)) {
-        qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "password");
+        qerror_report(QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "password");
         return -EINVAL;
     } else if (mon->rs) {
         readline_start(mon->rs, "Password: ", 1, readline_func, opaque);
@@ -935,7 +935,7 @@ static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_d
         int tls = qdict_get_try_bool(qdict, "tls", 0);
         if (!using_spice) {
             /* correct one? spice isn't a device ,,, */
-            qerror_report(/* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
+            qerror_report(QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  "spice");
             return -1;
         }
         if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
@@ -952,13 +952,13 @@ static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_d
     } else if ((s = qemu_chr_find(protocol)) != NULL) {
 	int fd = monitor_get_fd(mon, fdname);
 	if (qemu_chr_add_client(s, fd) < 0) {
-qerror_report(/* QERR_ADD_CLIENT_FAILED */ 0, "Could not add client");
+qerror_report(QERR_ADD_CLIENT_FAILED, "Could not add client");
 	    return -1;
 	}
 	return 0;
     }
 
-    qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
+    qerror_report(QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "protocol");
     return -1;
 }
 
@@ -974,25 +974,25 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
 
     if (strcmp(protocol, "spice") == 0) {
         if (!using_spice) {
-            qerror_report(/* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
+            qerror_report(QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  "spice");
             return -1;
         }
 
         if (port == -1 && tls_port == -1) {
-            qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "port/tls-port");
+            qerror_report(QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "port/tls-port");
             return -1;
         }
 
         ret = qemu_spice_migrate_info(hostname, port, tls_port, subject,
                                       cb, opaque);
         if (ret != 0) {
-            qerror_report(/* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+            qerror_report(QERR_UNDEFINED_ERROR, "An undefined error has occurred");
             return -1;
         }
         return 0;
     }
 
-    qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
+    qerror_report(QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "protocol");
     return -1;
 }
 
@@ -3857,7 +3857,7 @@ static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
          *
          * Action: Report an internal error to the client if in QMP.
          */
-        qerror_report(/* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+        qerror_report(QERR_UNDEFINED_ERROR, "An undefined error has occurred");
     }
 }
 
@@ -4160,7 +4160,7 @@ static int check_client_args_type(const QDict *client_args,
                 continue;
             }
             /* client arg doesn't exist */
-            qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", client_arg_name);
+            qerror_report(QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  client_arg_name);
             return -1;
         }
 
@@ -4173,7 +4173,7 @@ static int check_client_args_type(const QDict *client_args,
         case 'B':
         case 's':
             if (qobject_type(client_arg) != QTYPE_QSTRING) {
-                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "string");
+                qerror_report(QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  client_arg_name,  "string");
                 return -1;
             }
         break;
@@ -4182,21 +4182,21 @@ static int check_client_args_type(const QDict *client_args,
         case 'M':
         case 'o':
             if (qobject_type(client_arg) != QTYPE_QINT) {
-                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "int");
+                qerror_report(QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  client_arg_name,  "int");
                 return -1; 
             }
             break;
         case 'T':
             if (qobject_type(client_arg) != QTYPE_QINT &&
                 qobject_type(client_arg) != QTYPE_QFLOAT) {
-                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "number");
+                qerror_report(QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  client_arg_name,  "number");
                return -1; 
             }
             break;
         case 'b':
         case '-':
             if (qobject_type(client_arg) != QTYPE_QBOOL) {
-                qerror_report(/* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", client_arg_name, "bool");
+                qerror_report(QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  client_arg_name,  "bool");
                return -1; 
             }
             break;
@@ -4240,7 +4240,7 @@ static int check_mandatory_args(const QDict *cmd_args,
         } else if (qstring_get_str(type)[0] != '-' &&
                    qstring_get_str(type)[1] != '?' &&
                    !qdict_haskey(client_args, cmd_arg_name)) {
-            qerror_report(/* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", cmd_arg_name);
+            qerror_report(QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  cmd_arg_name);
             return -1;
         }
     }
@@ -4338,7 +4338,7 @@ static QDict *qmp_check_input_obj(QObject *input_obj)
     QDict *input_dict;
 
     if (qobject_type(input_obj) != QTYPE_QDICT) {
-        qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "object");
+        qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "Expected 'expected=%s' in QMP input",  "object");
         return NULL;
     }
 
@@ -4350,25 +4350,25 @@ static QDict *qmp_check_input_obj(QObject *input_obj)
 
         if (!strcmp(arg_name, "execute")) {
             if (qobject_type(arg_obj) != QTYPE_QSTRING) {
-                qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT_MEMBER */ 56, "QMP input object member 'member=%s' expects 'expected=%s'", "execute", "string");
+                qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "QMP input object member 'member=%s' expects 'expected=%s'",  "execute",  "string");
                 return NULL;
             }
             has_exec_key = 1;
         } else if (!strcmp(arg_name, "arguments")) {
             if (qobject_type(arg_obj) != QTYPE_QDICT) {
-                qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT_MEMBER */ 56, "QMP input object member 'member=%s' expects 'expected=%s'", "arguments", "object");
+                qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "QMP input object member 'member=%s' expects 'expected=%s'",  "arguments",  "object");
                 return NULL;
             }
         } else if (!strcmp(arg_name, "id")) {
             /* FIXME: check duplicated IDs for async commands */
         } else {
-            qerror_report(/* QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER */ 57, "QMP input object member 'member=%s' is unexpected", arg_name);
+            qerror_report(QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER, "QMP input object member 'member=%s' is unexpected",  arg_name);
             return NULL;
         }
     }
 
     if (!has_exec_key) {
-        qerror_report(/* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "execute");
+        qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "Expected 'expected=%s' in QMP input",  "execute");
         return NULL;
     }
 
@@ -4401,7 +4401,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     obj = json_parser_parse(tokens, NULL);
     if (!obj) {
         // FIXME: should be triggered in json_parser_parse()
-        qerror_report(/* QERR_JSON_PARSING */ 37, "Invalid JSON syntax");
+        qerror_report(QERR_JSON_PARSING, "Invalid JSON syntax");
         goto err_out;
     }
 
@@ -4417,13 +4417,13 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     cmd_name = qdict_get_str(input, "execute");
     trace_handle_qmp_command(mon, cmd_name);
     if (invalid_qmp_mode(mon, cmd_name)) {
-        qerror_report(/* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", cmd_name);
+        qerror_report(QERR_COMMAND_NOT_FOUND, "The command name=%s has not been found",  cmd_name);
         goto err_out;
     }
 
     cmd = qmp_find_cmd(cmd_name);
     if (!cmd) {
-        qerror_report(/* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", cmd_name);
+        qerror_report(QERR_COMMAND_NOT_FOUND, "The command name=%s has not been found",  cmd_name);
         goto err_out;
     }
 
@@ -4685,7 +4685,7 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
     }
 
     if (monitor_ctrl_mode(mon)) {
-        qerror_report(/* QERR_DEVICE_ENCRYPTED */ 10, "Device 'device=%s' is encrypted (filename=filename=%s)", bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs));
+        qerror_report(QERR_DEVICE_ENCRYPTED, "Device 'device=%s' is encrypted (filename=filename=%s)",  bdrv_get_device_name(bs),  bdrv_get_encrypted_filename(bs));
         return -1;
     }
 
diff --git a/qemu-option.c b/qemu-option.c
index df24142..0864a96 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -690,7 +690,7 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
         if (i == 0) {
             /* empty list -> allow any */;
         } else {
-            qerror_report(/* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", name);
+            qerror_report(QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  name);
             return -1;
         }
     }
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 14/14] error: change all error_set() calls to use the ErrClass enum
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (12 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum Luiz Capitulino
@ 2012-07-25 20:50 ` Luiz Capitulino
  2012-07-26  2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
  2012-07-26 15:54 ` Markus Armbruster
  15 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-25 20:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, aliguori, armbru, afaerber, peter.maydell

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 balloon.c                   | 10 +++---
 block.c                     |  4 +--
 block/qcow.c                |  2 +-
 block/stream.c              |  2 +-
 block/vdi.c                 |  2 +-
 block/vmdk.c                |  2 +-
 block/vpc.c                 |  2 +-
 block/vvfat.c               |  2 +-
 blockdev.c                  | 68 ++++++++++++++++++++--------------------
 cpus.c                      | 12 +++----
 dump-stub.c                 |  2 +-
 dump.c                      | 18 +++++------
 hmp.c                       |  2 +-
 hw/9pfs/virtio-9p.c         |  2 +-
 hw/ivshmem.c                |  2 +-
 hw/pci-stub.c               |  2 +-
 hw/qdev-addr.c              |  4 +--
 hw/qdev-monitor.c           |  2 +-
 hw/qdev-properties.c        | 42 ++++++++++++-------------
 hw/qdev.c                   |  6 ++--
 json-parser.c               |  2 +-
 migration.c                 |  6 ++--
 monitor.c                   |  8 ++---
 net.c                       | 18 +++++------
 qapi/qapi-visit-core.c      | 16 +++++-----
 qapi/qmp-dispatch.c         | 12 +++----
 qapi/qmp-input-visitor.c    | 16 +++++-----
 qapi/string-input-visitor.c |  8 ++---
 qemu-config.c               |  2 +-
 qemu-ga.c                   |  4 +--
 qemu-option.c               | 18 +++++------
 qemu-sockets.c              | 22 ++++++-------
 qga/commands-posix.c        | 76 ++++++++++++++++++++++-----------------------
 qga/commands-win32.c        | 44 +++++++++++++-------------
 qmp.c                       | 46 +++++++++++++--------------
 qom/object.c                | 20 ++++++------
 savevm.c                    |  6 ++--
 target-i386/cpu.c           | 10 +++---
 ui/vnc.c                    |  4 +--
 39 files changed, 263 insertions(+), 263 deletions(-)

diff --git a/balloon.c b/balloon.c
index a8bf9b6..60387df 100644
--- a/balloon.c
+++ b/balloon.c
@@ -99,14 +99,14 @@ BalloonInfo *qmp_query_balloon(Error **errp)
     BalloonInfo *info;
 
     if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, /* QERR_KVM_MISSING_CAP */ 38, "Using KVM without capability=%s, feature=%s unavailable", "synchronous MMU", "balloon");
+        error_set(errp, QERR_KVM_MISSING_CAP, "Using KVM without capability=%s,  feature=%s unavailable",  "synchronous MMU",  "balloon");
         return NULL;
     }
 
     info = g_malloc0(sizeof(*info));
 
     if (qemu_balloon_status(info) == 0) {
-        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "balloon");
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  "balloon");
         qapi_free_BalloonInfo(info);
         return NULL;
     }
@@ -117,16 +117,16 @@ BalloonInfo *qmp_query_balloon(Error **errp)
 void qmp_balloon(int64_t value, Error **errp)
 {
     if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, /* QERR_KVM_MISSING_CAP */ 38, "Using KVM without capability=%s, feature=%s unavailable", "synchronous MMU", "balloon");
+        error_set(errp, QERR_KVM_MISSING_CAP, "Using KVM without capability=%s,  feature=%s unavailable",  "synchronous MMU",  "balloon");
         return;
     }
 
     if (value <= 0) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "target", "a size");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "target",  "a size");
         return;
     }
     
     if (qemu_balloon(value) == 0) {
-        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "balloon");
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  "balloon");
     }
 }
diff --git a/block.c b/block.c
index c8d418a..be4861d 100644
--- a/block.c
+++ b/block.c
@@ -4034,7 +4034,7 @@ void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
     BlockJob *job;
 
     if (bs->job || bdrv_in_use(bs)) {
-        error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", bdrv_get_device_name(bs));
+        error_set(errp, QERR_DEVICE_IN_USE, "Device 'device=%s' is in use",  bdrv_get_device_name(bs));
         return NULL;
     }
     bdrv_set_in_use(bs, 1);
@@ -4079,7 +4079,7 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
     Error *local_err = NULL;
 
     if (!job->job_type->set_speed) {
-        error_set(errp, /* QERR_NOT_SUPPORTED */ 44, "Not supported");
+        error_set(errp, QERR_NOT_SUPPORTED, "Not supported");
         return;
     }
     job->job_type->set_speed(job, speed, &local_err);
diff --git a/block/qcow.c b/block/qcow.c
index b86d547..0e86156 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -180,7 +180,7 @@ static int qcow_open(BlockDriverState *bs, int flags)
     }
 
     /* Disable migration when qcow images are used */
-    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "qcow", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'",  "qcow",  bs->device_name,  "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     qemu_co_mutex_init(&s->lock);
diff --git a/block/stream.c b/block/stream.c
index 8ddaa59..81bb61e 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -168,7 +168,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)
     StreamBlockJob *s = container_of(job, StreamBlockJob, common);
 
     if (speed < 0) {
-        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "speed");
+        error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "speed");
         return;
     }
     ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
diff --git a/block/vdi.c b/block/vdi.c
index dadde29..ece4bd3 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -440,7 +440,7 @@ static int vdi_open(BlockDriverState *bs, int flags)
     }
 
     /* Disable migration when vdi images are used */
-    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vdi", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'",  "vdi",  bs->device_name,  "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
diff --git a/block/vmdk.c b/block/vmdk.c
index 49ee6cd..d38597c 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -663,7 +663,7 @@ static int vmdk_open(BlockDriverState *bs, int flags)
     qemu_co_mutex_init(&s->lock);
 
     /* Disable migration when VMDK images are used */
-    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vmdk", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'",  "vmdk",  bs->device_name,  "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
diff --git a/block/vpc.c b/block/vpc.c
index 662e3f8..d5118fe 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -255,7 +255,7 @@ static int vpc_open(BlockDriverState *bs, int flags)
     qemu_co_mutex_init(&s->lock);
 
     /* Disable migration when VHD images are used */
-    error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vpc", bs->device_name, "live migration");
+    error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'",  "vpc",  bs->device_name,  "live migration");
     migrate_add_blocker(s->migration_blocker);
 
     return 0;
diff --git a/block/vvfat.c b/block/vvfat.c
index cf9e9eb..796fd74 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1091,7 +1091,7 @@ DLOG(if (stderr == NULL) {
 
     /* Disable migration when vvfat is used rw */
     if (s->qcow) {
-        error_set(&s->migration_blocker, /* QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED */ 4, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'", "vvfat (rw)", bs->device_name, "live migration");
+        error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "Block format 'format=%s' used by device 'name=%s' does not support feature 'feature=%s'",  "vvfat (rw)",  bs->device_name,  "live migration");
         migrate_add_blocker(s->migration_blocker);
     }
 
diff --git a/blockdev.c b/blockdev.c
index 11c714f..3fc9d5a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -739,29 +739,29 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
 
         drv = bdrv_find_format(format);
         if (!drv) {
-            error_set(errp, /* QERR_INVALID_BLOCK_FORMAT */ 28, "Invalid block format 'name=%s'", format);
+            error_set(errp, QERR_INVALID_BLOCK_FORMAT, "Invalid block format 'name=%s'",  format);
             goto delete_and_fail;
         }
 
         states->old_bs = bdrv_find(device);
         if (!states->old_bs) {
-            error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+            error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
             goto delete_and_fail;
         }
 
         if (!bdrv_is_inserted(states->old_bs)) {
-            error_set(errp, /* QERR_DEVICE_HAS_NO_MEDIUM */ 12, "Device 'device=%s' has no medium", device);
+            error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, "Device 'device=%s' has no medium",  device);
             goto delete_and_fail;
         }
 
         if (bdrv_in_use(states->old_bs)) {
-            error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
+            error_set(errp, QERR_DEVICE_IN_USE, "Device 'device=%s' is in use",  device);
             goto delete_and_fail;
         }
 
         if (!bdrv_is_read_only(states->old_bs)) {
             if (bdrv_flush(states->old_bs)) {
-                error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
+                error_set(errp, QERR_IO_ERROR, "An IO error has occurred");
                 goto delete_and_fail;
             }
         }
@@ -770,7 +770,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
 
         proto_drv = bdrv_find_protocol(new_image_file);
         if (!proto_drv) {
-            error_set(errp, /* QERR_INVALID_BLOCK_FORMAT */ 28, "Invalid block format 'name=%s'", format);
+            error_set(errp, QERR_INVALID_BLOCK_FORMAT, "Invalid block format 'name=%s'",  format);
             goto delete_and_fail;
         }
 
@@ -781,7 +781,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
                                   states->old_bs->drv->format_name,
                                   NULL, -1, flags);
             if (ret) {
-                error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", new_image_file);
+                error_set(errp, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  new_image_file);
                 goto delete_and_fail;
             }
         }
@@ -791,7 +791,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
         ret = bdrv_open(states->new_bs, new_image_file,
                         flags | BDRV_O_NO_BACKING, drv);
         if (ret != 0) {
-            error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", new_image_file);
+            error_set(errp, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  new_image_file);
             goto delete_and_fail;
         }
     }
@@ -828,18 +828,18 @@ exit:
 static void eject_device(BlockDriverState *bs, int force, Error **errp)
 {
     if (bdrv_in_use(bs)) {
-        error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", bdrv_get_device_name(bs));
+        error_set(errp, QERR_DEVICE_IN_USE, "Device 'device=%s' is in use",  bdrv_get_device_name(bs));
         return;
     }
     if (!bdrv_dev_has_removable_media(bs)) {
-        error_set(errp, /* QERR_DEVICE_NOT_REMOVABLE */ 23, "Device 'device=%s' is not removable", bdrv_get_device_name(bs));
+        error_set(errp, QERR_DEVICE_NOT_REMOVABLE, "Device 'device=%s' is not removable",  bdrv_get_device_name(bs));
         return;
     }
 
     if (bdrv_dev_is_medium_locked(bs) && !bdrv_dev_is_tray_open(bs)) {
         bdrv_dev_eject_request(bs, force);
         if (!force) {
-            error_set(errp, /* QERR_DEVICE_LOCKED */ 16, "Device 'device=%s' is locked", bdrv_get_device_name(bs));
+            error_set(errp, QERR_DEVICE_LOCKED, "Device 'device=%s' is locked",  bdrv_get_device_name(bs));
             return;
         }
     }
@@ -853,7 +853,7 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
         return;
     }
 
@@ -867,16 +867,16 @@ void qmp_block_passwd(const char *device, const char *password, Error **errp)
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
         return;
     }
 
     err = bdrv_set_key(bs, password);
     if (err == -EINVAL) {
-        error_set(errp, /* QERR_DEVICE_NOT_ENCRYPTED */ 21, "Device 'device=%s' is not encrypted", bdrv_get_device_name(bs));
+        error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, "Device 'device=%s' is not encrypted",  bdrv_get_device_name(bs));
         return;
     } else if (err < 0) {
-        error_set(errp, /* QERR_INVALID_PASSWORD */ 34, "Password incorrect");
+        error_set(errp, QERR_INVALID_PASSWORD, "Password incorrect");
         return;
     }
 }
@@ -886,20 +886,20 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
                                     const char *password, Error **errp)
 {
     if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
-        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
+        error_set(errp, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  filename);
         return;
     }
 
     if (bdrv_key_required(bs)) {
         if (password) {
             if (bdrv_set_key(bs, password) < 0) {
-                error_set(errp, /* QERR_INVALID_PASSWORD */ 34, "Password incorrect");
+                error_set(errp, QERR_INVALID_PASSWORD, "Password incorrect");
             }
         } else {
-            error_set(errp, /* QERR_DEVICE_ENCRYPTED */ 10, "Device 'device=%s' is encrypted (filename=filename=%s)", bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs));
+            error_set(errp, QERR_DEVICE_ENCRYPTED, "Device 'device=%s' is encrypted (filename=filename=%s)",  bdrv_get_device_name(bs),  bdrv_get_encrypted_filename(bs));
         }
     } else if (password) {
-        error_set(errp, /* QERR_DEVICE_NOT_ENCRYPTED */ 21, "Device 'device=%s' is not encrypted", bdrv_get_device_name(bs));
+        error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, "Device 'device=%s' is not encrypted",  bdrv_get_device_name(bs));
     }
 }
 
@@ -913,14 +913,14 @@ void qmp_change_blockdev(const char *device, const char *filename,
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
         return;
     }
 
     if (format) {
         drv = bdrv_find_whitelisted_format(format);
         if (!drv) {
-            error_set(errp, /* QERR_INVALID_BLOCK_FORMAT */ 28, "Invalid block format 'name=%s'", format);
+            error_set(errp, QERR_INVALID_BLOCK_FORMAT, "Invalid block format 'name=%s'",  format);
             return;
         }
     }
@@ -947,7 +947,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
         return;
     }
 
@@ -959,7 +959,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
     io_limits.iops[BLOCK_IO_LIMIT_WRITE]= iops_wr;
 
     if (!do_check_io_limits(&io_limits)) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_COMBINATION */ 31, "Invalid parameter combination");
+        error_set(errp, QERR_INVALID_PARAMETER_COMBINATION, "Invalid parameter combination");
         return;
     }
 
@@ -1017,12 +1017,12 @@ void qmp_block_resize(const char *device, int64_t size, Error **errp)
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
         return;
     }
 
     if (size < 0) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "size", "a >0 size");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "size",  "a >0 size");
         return;
     }
 
@@ -1030,19 +1030,19 @@ void qmp_block_resize(const char *device, int64_t size, Error **errp)
     case 0:
         break;
     case -ENOMEDIUM:
-        error_set(errp, /* QERR_DEVICE_HAS_NO_MEDIUM */ 12, "Device 'device=%s' has no medium", device);
+        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, "Device 'device=%s' has no medium",  device);
         break;
     case -ENOTSUP:
-        error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+        error_set(errp, QERR_UNSUPPORTED, "this feature or command is not currently supported");
         break;
     case -EACCES:
-        error_set(errp, /* QERR_DEVICE_IS_READ_ONLY */ 15, "Device 'device=%s' is read only", device);
+        error_set(errp, QERR_DEVICE_IS_READ_ONLY, "Device 'device=%s' is read only",  device);
         break;
     case -EBUSY:
-        error_set(errp, /* QERR_DEVICE_IN_USE */ 14, "Device 'device=%s' is in use", device);
+        error_set(errp, QERR_DEVICE_IN_USE, "Device 'device=%s' is in use",  device);
         break;
     default:
-        error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+        error_set(errp, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
         break;
     }
 }
@@ -1095,14 +1095,14 @@ void qmp_block_stream(const char *device, bool has_base,
 
     bs = bdrv_find(device);
     if (!bs) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", device);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  device);
         return;
     }
 
     if (base) {
         base_bs = bdrv_find_backing_image(bs, base);
         if (base_bs == NULL) {
-            error_set(errp, /* QERR_BASE_NOT_FOUND */ 3, "Base 'base=%s' not found", base);
+            error_set(errp, QERR_BASE_NOT_FOUND, "Base 'base=%s' not found",  base);
             return;
         }
     }
@@ -1138,7 +1138,7 @@ void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp)
     BlockJob *job = find_block_job(device);
 
     if (!job) {
-        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", device);
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  device);
         return;
     }
 
@@ -1150,7 +1150,7 @@ void qmp_block_job_cancel(const char *device, Error **errp)
     BlockJob *job = find_block_job(device);
 
     if (!job) {
-        error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", device);
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  device);
         return;
     }
 
diff --git a/cpus.c b/cpus.c
index f72c117..c6619a6 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1246,13 +1246,13 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
     }
 
     if (env == NULL) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "cpu-index", "a CPU number");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "cpu-index",  "a CPU number");
         return;
     }
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
+        error_set(errp, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  filename);
         return;
     }
 
@@ -1262,7 +1262,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
             l = size;
         cpu_memory_rw_debug(env, addr, buf, l, 0);
         if (fwrite(buf, 1, l, f) != l) {
-            error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
+            error_set(errp, QERR_IO_ERROR, "An IO error has occurred");
             goto exit;
         }
         addr += l;
@@ -1282,7 +1282,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
 
     f = fopen(filename, "wb");
     if (!f) {
-        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
+        error_set(errp, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  filename);
         return;
     }
 
@@ -1292,7 +1292,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
             l = size;
         cpu_physical_memory_rw(addr, buf, l, 0);
         if (fwrite(buf, 1, l, f) != l) {
-            error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
+            error_set(errp, QERR_IO_ERROR, "An IO error has occurred");
             goto exit;
         }
         addr += l;
@@ -1316,6 +1316,6 @@ void qmp_inject_nmi(Error **errp)
         }
     }
 #else
-    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(errp, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 #endif
 }
diff --git a/dump-stub.c b/dump-stub.c
index 537c947..ec51e7f 100644
--- a/dump-stub.c
+++ b/dump-stub.c
@@ -21,7 +21,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
                            int64_t begin, bool has_length, int64_t length,
                            Error **errp)
 {
-    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(errp, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 }
 
 int cpu_write_elf64_note(write_core_dump_function f,
diff --git a/dump.c b/dump.c
index 7cc27f9..cc427ba 100644
--- a/dump.c
+++ b/dump.c
@@ -721,7 +721,7 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
     s->length = length;
     s->start = get_start_block(s);
     if (s->start == -1) {
-        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "begin");
+        error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "begin");
         goto cleanup;
     }
 
@@ -741,14 +741,14 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
 
     ret = cpu_get_dump_info(&s->dump_info);
     if (ret < 0) {
-        error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+        error_set(errp, QERR_UNSUPPORTED, "this feature or command is not currently supported");
         goto cleanup;
     }
 
     s->note_size = cpu_get_note_size(s->dump_info.d_class,
                                      s->dump_info.d_machine, nr_cpus);
     if (ret < 0) {
-        error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+        error_set(errp, QERR_UNSUPPORTED, "this feature or command is not currently supported");
         goto cleanup;
     }
 
@@ -826,11 +826,11 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     int ret;
 
     if (has_begin && !has_length) {
-        error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "length");
+        error_set(errp, QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "length");
         return;
     }
     if (!has_begin && has_length) {
-        error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "begin");
+        error_set(errp, QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "begin");
         return;
     }
 
@@ -838,7 +838,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     if (strstart(file, "fd:", &p)) {
         fd = monitor_get_fd(cur_mon, p);
         if (fd == -1) {
-            error_set(errp, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", p);
+            error_set(errp, QERR_FD_NOT_FOUND, "File descriptor named 'name=%s' not found",  p);
             return;
         }
     }
@@ -847,13 +847,13 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     if  (strstart(file, "file:", &p)) {
         fd = qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR);
         if (fd < 0) {
-            error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", p);
+            error_set(errp, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  p);
             return;
         }
     }
 
     if (fd == -1) {
-        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
+        error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "protocol");
         return;
     }
 
@@ -866,7 +866,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     }
 
     if (create_vmcore(s) < 0 && !error_is_set(s->errp)) {
-        error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
+        error_set(errp, QERR_IO_ERROR, "An IO error has occurred");
     }
 
     g_free(s);
diff --git a/hmp.c b/hmp.c
index ceeb8da..045b911 100644
--- a/hmp.c
+++ b/hmp.c
@@ -707,7 +707,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
     if (!filename) {
         /* In the future, if 'snapshot-file' is not specified, the snapshot
            will be taken internally. Today it's actually required. */
-        error_set(&errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "snapshot-file");
+        error_set(&errp, QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "snapshot-file");
         hmp_handle_error(mon, &errp);
         return;
     }
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 8080582..d833e18 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -985,7 +985,7 @@ static void v9fs_attach(void *opaque)
                              qid.type, qid.version, qid.path);
     s->root_fid = fid;
     /* disable migration */
-    error_set(&s->migration_blocker, /* QERR_VIRTFS_FEATURE_BLOCKS_MIGRATION */ 69, "Migration is disabled when VirtFS export path 'path=%s' is mounted in the guest using mount_tag 'tag=%s'", s->ctx.fs_root ? s->ctx.fs_root : "NULL", s->tag);
+    error_set(&s->migration_blocker, QERR_VIRTFS_FEATURE_BLOCKS_MIGRATION, "Migration is disabled when VirtFS export path 'path=%s' is mounted in the guest using mount_tag 'tag=%s'",  s->ctx.fs_root ? s->ctx.fs_root : "NULL",  s->tag);
     migrate_add_blocker(s->migration_blocker);
 out:
     put_fid(pdu, fidp);
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index f95cd60..cf042b4 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -681,7 +681,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     if (s->role_val == IVSHMEM_PEER) {
-        error_set(&s->migration_blocker, /* QERR_DEVICE_FEATURE_BLOCKS_MIGRATION */ 11, "Migration is disabled when using feature 'feature=%s' in device 'device=%s'", "ivshmem", "peer mode");
+        error_set(&s->migration_blocker, QERR_DEVICE_FEATURE_BLOCKS_MIGRATION, "Migration is disabled when using feature 'feature=%s' in device 'device=%s'",  "ivshmem",  "peer mode");
         migrate_add_blocker(s->migration_blocker);
     }
 
diff --git a/hw/pci-stub.c b/hw/pci-stub.c
index 448c21e..8ccfb6a 100644
--- a/hw/pci-stub.c
+++ b/hw/pci-stub.c
@@ -25,7 +25,7 @@
 
 PciInfoList *qmp_query_pci(Error **errp)
 {
-    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(errp, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return NULL;
 }
 
diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
index c002ecd..a011f67 100644
--- a/hw/qdev-addr.c
+++ b/hw/qdev-addr.c
@@ -40,7 +40,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     int64_t value;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -52,7 +52,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     if ((uint64_t)value <= (uint64_t) ~(target_phys_addr_t)0) {
         *ptr = value;
     } else {
-        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", dev->id?:"", name, value, (uint64_t) 0, (uint64_t) ~(target_phys_addr_t)0);
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64",  maximum: max=%"PRId64")",  dev->id?:"",  name,  value,  (uint64_t) 0,  (uint64_t) ~(target_phys_addr_t)0);
     }
 }
 
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 03bb21d..dfa7491 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -600,7 +600,7 @@ void qmp_device_del(const char *id, Error **errp)
 
     dev = qdev_find_recursive(sysbus_get_default(), id);
     if (NULL == dev) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", id);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  id);
         return;
     }
 
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index a6a17d7..95020ad 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -35,7 +35,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
     int ret;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -73,7 +73,7 @@ static void set_enum(Object *obj, Visitor *v, void *opaque,
     int *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -125,7 +125,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
     bool value;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -165,7 +165,7 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
     uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -232,7 +232,7 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
     uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -265,7 +265,7 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
     uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -290,7 +290,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
     int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -363,7 +363,7 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque,
     uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -451,7 +451,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -656,7 +656,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     VLANState *vlan;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -671,7 +671,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     }
     vlan = qemu_find_vlan(id, 1);
     if (!vlan) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, prop->info->name);
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name,  prop->info->name);
         return;
     }
     *ptr = vlan;
@@ -725,7 +725,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
     char *str, *p;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -813,7 +813,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -825,7 +825,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
         if (local_err) {
             error_propagate(errp, local_err);
         } else if (value < -1 || value > 255) {
-            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "pci_devfn");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name ? name : "null",  "pci_devfn");
         } else {
             *ptr = value;
         }
@@ -882,7 +882,7 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
     const int64_t max = 32768;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -892,13 +892,13 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", dev->id?:"", name, (int64_t)value, min, max);
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64",  maximum: max=%"PRId64")",  dev->id?:"",  name,  (int64_t)value,  min,  max);
         return;
     }
 
     /* We rely on power-of-2 blocksizes for bitmasks */
     if ((value & (value - 1)) != 0) {
-        error_set(errp, /* QERR_PROPERTY_VALUE_NOT_POWER_OF2 */ 51, "Property 'device=%s.property=%s' doesn't take value 'value=%"PRId64"', it's not a power of 2", dev->id?:"", name, (int64_t)value);
+        error_set(errp, QERR_PROPERTY_VALUE_NOT_POWER_OF2, "Property 'device=%s.property=%s' doesn't take value 'value=%"PRId64"',  it's not a power of 2",  dev->id?:"",  name,  (int64_t)value);
         return;
     }
 
@@ -948,7 +948,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
     unsigned int slot = 0, func = 0;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
@@ -1055,14 +1055,14 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
 {
     switch (ret) {
     case -EEXIST:
-        error_set(errp, /* QERR_PROPERTY_VALUE_IN_USE */ 49, "Property 'device=%s.property=%s' can't take value 'value=%s', it's in use", object_get_typename(OBJECT(dev)), prop->name, value);
+        error_set(errp, QERR_PROPERTY_VALUE_IN_USE, "Property 'device=%s.property=%s' can't take value 'value=%s',  it's in use",  object_get_typename(OBJECT(dev)),  prop->name,  value);
         break;
     default:
     case -EINVAL:
-        error_set(errp, /* QERR_PROPERTY_VALUE_BAD */ 48, "Property 'device=%s.property=%s' doesn't take value 'value=%s'", object_get_typename(OBJECT(dev)), prop->name, value);
+        error_set(errp, QERR_PROPERTY_VALUE_BAD, "Property 'device=%s.property=%s' doesn't take value 'value=%s'",  object_get_typename(OBJECT(dev)),  prop->name,  value);
         break;
     case -ENOENT:
-        error_set(errp, /* QERR_PROPERTY_VALUE_NOT_FOUND */ 50, "Property 'device=%s.property=%s' can't find value 'value=%s'", object_get_typename(OBJECT(dev)), prop->name, value);
+        error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND, "Property 'device=%s.property=%s' can't find value 'value=%s'",  object_get_typename(OBJECT(dev)),  prop->name,  value);
         break;
     case 0:
         break;
diff --git a/hw/qdev.c b/hw/qdev.c
index 390403c..e33b86e 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -199,7 +199,7 @@ void qdev_unplug(DeviceState *dev, Error **errp)
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
     if (!dev->parent_bus->allow_hotplug) {
-        error_set(errp, /* QERR_BUS_NO_HOTPLUG */ 6, "Bus 'bus=%s' does not support hotplugging", dev->parent_bus->name);
+        error_set(errp, QERR_BUS_NO_HOTPLUG, "Bus 'bus=%s' does not support hotplugging",  dev->parent_bus->name);
         return;
     }
     assert(dc->unplug != NULL);
@@ -207,7 +207,7 @@ void qdev_unplug(DeviceState *dev, Error **errp)
     qdev_hot_removed = true;
 
     if (dc->unplug(dev) < 0) {
-        error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+        error_set(errp, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
         return;
     }
 }
@@ -570,7 +570,7 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
     int ret;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
         return;
     }
 
diff --git a/json-parser.c b/json-parser.c
index c113064..d1ff507 100644
--- a/json-parser.c
+++ b/json-parser.c
@@ -105,7 +105,7 @@ static void GCC_FMT_ATTR(3, 4) parse_error(JSONParserContext *ctxt,
         error_free(ctxt->err);
         ctxt->err = NULL;
     }
-    error_set(&ctxt->err, /* QERR_JSON_PARSE_ERROR */ 36, "JSON parse error, message=%s", message);
+    error_set(&ctxt->err, QERR_JSON_PARSE_ERROR, "JSON parse error,  message=%s",  message);
 }
 
 /**
diff --git a/migration.c b/migration.c
index d1788c8..ab5d03c 100644
--- a/migration.c
+++ b/migration.c
@@ -412,7 +412,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     params.shared = inc;
 
     if (s->state == MIG_STATE_ACTIVE) {
-        error_set(errp, /* QERR_MIGRATION_ACTIVE */ 39, "There\'s a migration process in progress");
+        error_set(errp, QERR_MIGRATION_ACTIVE, "There\'s a migration process in progress");
         return;
     }
 
@@ -438,7 +438,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         ret = fd_start_outgoing_migration(s, p);
 #endif
     } else {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "uri", "a valid migration protocol");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "uri",  "a valid migration protocol");
         return;
     }
 
@@ -446,7 +446,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         if (!error_is_set(errp)) {
             DPRINTF("migration failed: %s\n", strerror(-ret));
             /* FIXME: we should return meaningful errors */
-            error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+            error_set(errp, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
         }
         return;
     }
diff --git a/monitor.c b/monitor.c
index 62d56a4..550f688 100644
--- a/monitor.c
+++ b/monitor.c
@@ -626,7 +626,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
         int ret = monitor_set_cpu(cpu_index);
         if (ret < 0) {
             cur_mon = old_mon;
-            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "cpu-index", "a CPU number");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "cpu-index",  "a CPU number");
             goto out;
         }
     }
@@ -2284,12 +2284,12 @@ void qmp_getfd(const char *fdname, Error **errp)
 
     fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
     if (fd == -1) {
-        error_set(errp, /* QERR_FD_NOT_SUPPLIED */ 26, "No file descriptor supplied via SCM_RIGHTS");
+        error_set(errp, QERR_FD_NOT_SUPPLIED, "No file descriptor supplied via SCM_RIGHTS");
         return;
     }
 
     if (qemu_isdigit(fdname[0])) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "fdname", "a name not starting with a digit");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "fdname",  "a name not starting with a digit");
         return;
     }
 
@@ -2326,7 +2326,7 @@ void qmp_closefd(const char *fdname, Error **errp)
         return;
     }
 
-    error_set(errp, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", fdname);
+    error_set(errp, QERR_FD_NOT_FOUND, "File descriptor named 'name=%s' not found",  fdname);
 }
 
 static void do_loadvm(Monitor *mon, const QDict *qdict)
diff --git a/net.c b/net.c
index bf4a7c3..a8d85b3 100644
--- a/net.c
+++ b/net.c
@@ -1089,7 +1089,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
 
     type = qemu_opt_get(opts, "type");
     if (!type) {
-        error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "type");
+        error_set(errp, QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "type");
         return -1;
     }
 
@@ -1105,20 +1105,20 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
             strcmp(type, "vde") != 0 &&
 #endif
             strcmp(type, "socket") != 0) {
-            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "type", "a netdev backend type");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "type",  "a netdev backend type");
             return -1;
         }
 
         if (qemu_opt_get(opts, "vlan")) {
-            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "vlan");
+            error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "vlan");
             return -1;
         }
         if (qemu_opt_get(opts, "name")) {
-            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "name");
+            error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "name");
             return -1;
         }
         if (!qemu_opts_id(opts)) {
-            error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "id");
+            error_set(errp, QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "id");
             return -1;
         }
     }
@@ -1153,7 +1153,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
                 ret = net_client_types[i].init(opts, name, vlan);
                 if (ret < 0) {
                     /* TODO push error reporting into init() methods */
-                    error_set(errp, /* QERR_DEVICE_INIT_FAILED */ 13, "Device 'device=%s' could not be initialized", type);
+                    error_set(errp, QERR_DEVICE_INIT_FAILED, "Device 'device=%s' could not be initialized",  type);
                     return -1;
                 }
             }
@@ -1161,7 +1161,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
         }
     }
 
-    error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "type", "a network client type");
+    error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "type",  "a network client type");
     return -1;
 }
 
@@ -1273,7 +1273,7 @@ void qmp_netdev_del(const char *id, Error **errp)
 
     vc = qemu_find_netdev(id);
     if (!vc) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", id);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  id);
         return;
     }
 
@@ -1336,7 +1336,7 @@ void qmp_set_link(const char *name, bool up, Error **errp)
 done:
 
     if (!vc) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", name);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  name);
         return;
     }
 
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index e652039..482109a 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -107,7 +107,7 @@ void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < 0 || value > UINT8_MAX) {
-                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "uint8_t");
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name ? name : "null",  "uint8_t");
                 return;
             }
             *obj = value;
@@ -125,7 +125,7 @@ void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < 0 || value > UINT16_MAX) {
-                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "uint16_t");
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name ? name : "null",  "uint16_t");
                 return;
             }
             *obj = value;
@@ -143,7 +143,7 @@ void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < 0 || value > UINT32_MAX) {
-                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "uint32_t");
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name ? name : "null",  "uint32_t");
                 return;
             }
             *obj = value;
@@ -175,7 +175,7 @@ void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < INT8_MIN || value > INT8_MAX) {
-                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "int8_t");
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name ? name : "null",  "int8_t");
                 return;
             }
             *obj = value;
@@ -193,7 +193,7 @@ void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < INT16_MIN || value > INT16_MAX) {
-                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "int16_t");
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name ? name : "null",  "int16_t");
                 return;
             }
             *obj = value;
@@ -211,7 +211,7 @@ void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
             value = *obj;
             v->type_int(v, &value, name, errp);
             if (value < INT32_MIN || value > INT32_MAX) {
-                error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name ? name : "null", "int32_t");
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name ? name : "null",  "int32_t");
                 return;
             }
             *obj = value;
@@ -262,7 +262,7 @@ void output_type_enum(Visitor *v, int *obj, const char *strings[],
     assert(strings);
     while (strings[i++] != NULL);
     if (value < 0 || value >= i - 1) {
-        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", name ? name : "null");
+        error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  name ? name : "null");
         return;
     }
 
@@ -292,7 +292,7 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],
     }
 
     if (strings[value] == NULL) {
-        error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", enum_str);
+        error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  enum_str);
         g_free(enum_str);
         return;
     }
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index df2c12e..5dcc23f 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -27,7 +27,7 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
     QDict *dict = NULL;
 
     if (qobject_type(request) != QTYPE_QDICT) {
-        error_set(errp, /* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "request is not a dictionary");
+        error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "Expected 'expected=%s' in QMP input",  "request is not a dictionary");
         return NULL;
     }
 
@@ -40,18 +40,18 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
 
         if (!strcmp(arg_name, "execute")) {
             if (qobject_type(arg_obj) != QTYPE_QSTRING) {
-                error_set(errp, /* QERR_QMP_BAD_INPUT_OBJECT_MEMBER */ 56, "QMP input object member 'member=%s' expects 'expected=%s'", "execute", "string");
+                error_set(errp, QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "QMP input object member 'member=%s' expects 'expected=%s'",  "execute",  "string");
                 return NULL;
             }
             has_exec_key = true;
         } else if (strcmp(arg_name, "arguments")) {
-            error_set(errp, /* QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER */ 57, "QMP input object member 'member=%s' is unexpected", arg_name);
+            error_set(errp, QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER, "QMP input object member 'member=%s' is unexpected",  arg_name);
             return NULL;
         }
     }
 
     if (!has_exec_key) {
-        error_set(errp, /* QERR_QMP_BAD_INPUT_OBJECT */ 55, "Expected 'expected=%s' in QMP input", "execute");
+        error_set(errp, QERR_QMP_BAD_INPUT_OBJECT, "Expected 'expected=%s' in QMP input",  "execute");
         return NULL;
     }
 
@@ -74,11 +74,11 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)
     command = qdict_get_str(dict, "execute");
     cmd = qmp_find_command(command);
     if (cmd == NULL) {
-        error_set(errp, /* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", command);
+        error_set(errp, QERR_COMMAND_NOT_FOUND, "The command name=%s has not been found",  command);
         return NULL;
     }
     if (!cmd->enabled) {
-        error_set(errp, /* QERR_COMMAND_DISABLED */ 8, "The command name=%s has been disabled for this instance", command);
+        error_set(errp, QERR_COMMAND_DISABLED, "The command name=%s has been disabled for this instance",  command);
         return NULL;
     }
 
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index 351a4a6..929b6e4 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -70,7 +70,7 @@ static void qmp_input_push(QmpInputVisitor *qiv, QObject *obj, Error **errp)
     GHashTable *h;
 
     if (qiv->nb_stack >= QIV_STACK_SIZE) {
-        error_set(errp, /* QERR_BUFFER_OVERRUN */ 5, "An internal buffer overran");
+        error_set(errp, QERR_BUFFER_OVERRUN, "An internal buffer overran");
         return;
     }
 
@@ -104,7 +104,7 @@ static void qmp_input_pop(QmpInputVisitor *qiv, Error **errp)
             if (g_hash_table_size(top_ht)) {
                 const char *key;
                 g_hash_table_find(top_ht, always_true, &key);
-                error_set(errp, /* QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER */ 57, "QMP input object member 'member=%s' is unexpected", key);
+                error_set(errp, QERR_QMP_EXTRA_INPUT_OBJECT_MEMBER, "QMP input object member 'member=%s' is unexpected",  key);
             }
             g_hash_table_unref(top_ht);
         }
@@ -121,7 +121,7 @@ static void qmp_input_start_struct(Visitor *v, void **obj, const char *kind,
     Error *err = NULL;
 
     if (!qobj || qobject_type(qobj) != QTYPE_QDICT) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "QDict");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "QDict");
         return;
     }
 
@@ -149,7 +149,7 @@ static void qmp_input_start_list(Visitor *v, const char *name, Error **errp)
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QLIST) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "list");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "list");
         return;
     }
 
@@ -200,7 +200,7 @@ static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name,
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QINT) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "integer");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "integer");
         return;
     }
 
@@ -214,7 +214,7 @@ static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name,
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QBOOL) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "boolean");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "boolean");
         return;
     }
 
@@ -228,7 +228,7 @@ static void qmp_input_type_str(Visitor *v, char **obj, const char *name,
     QObject *qobj = qmp_input_get_object(qiv, name);
 
     if (!qobj || qobject_type(qobj) != QTYPE_QSTRING) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "string");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "string");
         return;
     }
 
@@ -243,7 +243,7 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name,
 
     if (!qobj || (qobject_type(qobj) != QTYPE_QFLOAT &&
         qobject_type(qobj) != QTYPE_QINT)) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "number");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "number");
         return;
     }
 
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index d0eba4e..e01237c 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -33,7 +33,7 @@ static void parse_type_int(Visitor *v, int64_t *obj, const char *name,
         val = strtoll(siv->string, &endp, 0);
     }
     if (!siv->string || errno || endp == siv->string || *endp) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "integer");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "integer");
         return;
     }
 
@@ -60,7 +60,7 @@ static void parse_type_bool(Visitor *v, bool *obj, const char *name,
         }
     }
 
-    error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "boolean");
+    error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "boolean");
 }
 
 static void parse_type_str(Visitor *v, char **obj, const char *name,
@@ -70,7 +70,7 @@ static void parse_type_str(Visitor *v, char **obj, const char *name,
     if (siv->string) {
         *obj = g_strdup(siv->string);
     } else {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "string");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "string");
     }
 }
 
@@ -86,7 +86,7 @@ static void parse_type_number(Visitor *v, double *obj, const char *name,
         val = strtod(siv->string, &endp);
     }
     if (!siv->string || errno || endp == siv->string || *endp) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name ? name : "null", "number");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name ? name : "null",  "number");
         return;
     }
 
diff --git a/qemu-config.c b/qemu-config.c
index 09c3be4..46d2158 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -654,7 +654,7 @@ static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
             break;
     }
     if (lists[i] == NULL) {
-        error_set(errp, /* QERR_INVALID_OPTION_GROUP */ 29, "There is no option group 'group=%s'", group);
+        error_set(errp, QERR_INVALID_OPTION_GROUP, "There is no option group 'group=%s'",  group);
     }
     return lists[i];
 }
diff --git a/qemu-ga.c b/qemu-ga.c
index d1e2b0c..28d63e3 100644
--- a/qemu-ga.c
+++ b/qemu-ga.c
@@ -511,7 +511,7 @@ static void process_event(JSONMessageParser *parser, QList *tokens)
         qdict = qdict_new();
         if (!err) {
             g_warning("failed to parse event: unknown error");
-            error_set(&err, /* QERR_JSON_PARSING */ 37, "Invalid JSON syntax");
+            error_set(&err, QERR_JSON_PARSING, "Invalid JSON syntax");
         } else {
             g_warning("failed to parse event: %s", error_get_pretty(err));
         }
@@ -531,7 +531,7 @@ static void process_event(JSONMessageParser *parser, QList *tokens)
             QDECREF(qdict);
             qdict = qdict_new();
             g_warning("unrecognized payload format");
-            error_set(&err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+            error_set(&err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
             qdict_put_obj(qdict, "error", error_get_qobject(err));
             error_free(err);
         }
diff --git a/qemu-option.c b/qemu-option.c
index 0864a96..c7a73b7 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -178,7 +178,7 @@ static void parse_option_bool(const char *name, const char *value, bool *ret,
         } else if (!strcmp(value, "off")) {
             *ret = 0;
         } else {
-            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "'on' or 'off'");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name,  "'on' or 'off'");
         }
     } else {
         *ret = 1;
@@ -194,12 +194,12 @@ static void parse_option_number(const char *name, const char *value,
     if (value != NULL) {
         number = strtoull(value, &postfix, 0);
         if (*postfix != '\0') {
-            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a number");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name,  "a number");
             return;
         }
         *ret = number;
     } else {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a number");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name,  "a number");
     }
 }
 
@@ -230,13 +230,13 @@ static void parse_option_size(const char *name, const char *value,
             *ret = (uint64_t) sizef;
             break;
         default:
-            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a size");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name,  "a size");
             error_printf_unless_qmp("You may use k, M, G or T suffixes for "
                     "kilobytes, megabytes, gigabytes and terabytes.\n");
             return;
         }
     } else {
-        error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", name, "a size");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  name,  "a size");
     }
 }
 
@@ -629,7 +629,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         if (i == 0) {
             /* empty list -> allow any */;
         } else {
-            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", name);
+            error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  name);
             return;
         }
     }
@@ -761,14 +761,14 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
 
     if (id) {
         if (!id_wellformed(id)) {
-            error_set(errp, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "id", "an identifier");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "id",  "an identifier");
             error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
             return NULL;
         }
         opts = qemu_opts_find(list, id);
         if (opts != NULL) {
             if (fail_if_exists && !list->merge_lists) {
-                error_set(errp, /* QERR_DUPLICATE_ID */ 24, "Duplicate ID 'id=%s' for object=%s", id, list->name);
+                error_set(errp, QERR_DUPLICATE_ID, "Duplicate ID 'id=%s' for object=%s",  id,  list->name);
                 return NULL;
             } else {
                 return opts;
@@ -1089,7 +1089,7 @@ void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp)
             }
         }
         if (desc[i].name == NULL) {
-            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", opt->name);
+            error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  opt->name);
             return;
         }
 
diff --git a/qemu-sockets.c b/qemu-sockets.c
index 1051740..c65db33 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -120,7 +120,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
     if ((qemu_opt_get(opts, "host") == NULL) ||
         (qemu_opt_get(opts, "port") == NULL)) {
         fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
-        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
+        error_set(errp, QERR_SOCK_CREATE_FAILED, "Failed to create socket");
         return -1;
     }
     pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
@@ -139,7 +139,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
     if (rc != 0) {
         fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
                 gai_strerror(rc));
-        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
+        error_set(errp, QERR_SOCK_CREATE_FAILED, "Failed to create socket");
         return -1;
     }
 
@@ -153,7 +153,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
             fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
                     inet_strfamily(e->ai_family), strerror(errno));
             if (!e->ai_next) {
-                error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
+                error_set(errp, QERR_SOCK_CREATE_FAILED, "Failed to create socket");
             }
             continue;
         }
@@ -179,7 +179,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
                         inet_strfamily(e->ai_family), uaddr, inet_getport(e),
                         strerror(errno));
                 if (!e->ai_next) {
-                    error_set(errp, /* QERR_SOCK_BIND_FAILED */ 60, "Failed to bind socket");
+                    error_set(errp, QERR_SOCK_BIND_FAILED, "Failed to bind socket");
                 }
             }
         }
@@ -191,7 +191,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
 
 listen:
     if (listen(slisten,1) != 0) {
-        error_set(errp, /* QERR_SOCK_LISTEN_FAILED */ 64, "Failed to set socket to listening mode");
+        error_set(errp, QERR_SOCK_LISTEN_FAILED, "Failed to set socket to listening mode");
         perror("listen");
         closesocket(slisten);
         freeaddrinfo(res);
@@ -226,7 +226,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
     block = qemu_opt_get_bool(opts, "block", 0);
     if (addr == NULL || port == NULL) {
         fprintf(stderr, "inet_connect: host and/or port not specified\n");
-        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
+        error_set(errp, QERR_SOCK_CREATE_FAILED, "Failed to create socket");
         return -1;
     }
 
@@ -239,7 +239,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
     if (0 != (rc = getaddrinfo(addr, port, &ai, &res))) {
         fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
                 gai_strerror(rc));
-        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
+        error_set(errp, QERR_SOCK_CREATE_FAILED, "Failed to create socket");
 	return -1;
     }
 
@@ -274,7 +274,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
   #else
         if (!block && (rc == -EINPROGRESS)) {
   #endif
-            error_set(errp, /* QERR_SOCK_CONNECT_INPROGRESS */ 62, "Connection can not be completed immediately");
+            error_set(errp, QERR_SOCK_CONNECT_INPROGRESS, "Connection can not be completed immediately");
         } else if (rc < 0) {
             if (NULL == e->ai_next)
                 fprintf(stderr, "%s: connect(%s,%s,%s,%s): %s\n", __FUNCTION__,
@@ -287,7 +287,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)
         freeaddrinfo(res);
         return sock;
     }
-    error_set(errp, /* QERR_SOCK_CONNECT_FAILED */ 61, "Failed to connect to socket");
+    error_set(errp, QERR_SOCK_CONNECT_FAILED, "Failed to connect to socket");
     freeaddrinfo(res);
     return -1;
 }
@@ -479,7 +479,7 @@ int inet_listen(const char *str, char *ostr, int olen,
             }
         }
     } else {
-        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
+        error_set(errp, QERR_SOCK_CREATE_FAILED, "Failed to create socket");
     }
     qemu_opts_del(opts);
     return sock;
@@ -497,7 +497,7 @@ int inet_connect(const char *str, bool block, Error **errp)
         }
         sock = inet_connect_opts(opts, errp);
     } else {
-        error_set(errp, /* QERR_SOCK_CREATE_FAILED */ 63, "Failed to create socket");
+        error_set(errp, QERR_SOCK_CREATE_FAILED, "Failed to create socket");
     }
     qemu_opts_del(opts);
     return sock;
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index e881f3e..24a46a4 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -60,7 +60,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
     } else if (strcmp(mode, "reboot") == 0) {
         shutdown_flag = "-r";
     } else {
-        error_set(err, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "mode", "halt|powerdown|reboot");
+        error_set(err, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "mode",  "halt|powerdown|reboot");
         return;
     }
 
@@ -87,7 +87,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
     }
 
 exit_err:
-    error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+    error_set(err, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
 }
 
 typedef struct GuestFileHandle {
@@ -136,7 +136,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     slog("guest-file-open called, filepath: %s, mode: %s", path, mode);
     fh = fopen(path, mode);
     if (!fh) {
-        error_set(err, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", path);
+        error_set(err, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  path);
         return -1;
     }
 
@@ -147,7 +147,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E
     ret = fcntl(fd, F_GETFL);
     ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
     if (ret == -1) {
-        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fcntl() failed");
+        error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "fcntl() failed");
         fclose(fh);
         return -1;
     }
@@ -164,13 +164,13 @@ void qmp_guest_file_close(int64_t handle, Error **err)
 
     slog("guest-file-close called, handle: %ld", handle);
     if (!gfh) {
-        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
+        error_set(err, QERR_FD_NOT_FOUND, "File descriptor named 'name=%s' not found",  "handle");
         return;
     }
 
     ret = fclose(gfh->fh);
     if (ret == -1) {
-        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fclose() failed");
+        error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "fclose() failed");
         return;
     }
 
@@ -188,14 +188,14 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
     size_t read_count;
 
     if (!gfh) {
-        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
+        error_set(err, QERR_FD_NOT_FOUND, "File descriptor named 'name=%s' not found",  "handle");
         return NULL;
     }
 
     if (!has_count) {
         count = QGA_READ_COUNT_DEFAULT;
     } else if (count < 0) {
-        error_set(err, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "count");
+        error_set(err, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "count");
         return NULL;
     }
 
@@ -204,7 +204,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
     read_count = fread(buf, 1, count, fh);
     if (ferror(fh)) {
         slog("guest-file-read failed, handle: %ld", handle);
-        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fread() failed");
+        error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "fread() failed");
     } else {
         buf[read_count] = 0;
         read_data = g_malloc0(sizeof(GuestFileRead));
@@ -231,7 +231,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
     FILE *fh;
 
     if (!gfh) {
-        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
+        error_set(err, QERR_FD_NOT_FOUND, "File descriptor named 'name=%s' not found",  "handle");
         return NULL;
     }
 
@@ -242,14 +242,14 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
         count = buf_len;
     } else if (count < 0 || count > buf_len) {
         g_free(buf);
-        error_set(err, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "count");
+        error_set(err, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "count");
         return NULL;
     }
 
     write_count = fwrite(buf, 1, count, fh);
     if (ferror(fh)) {
         slog("guest-file-write failed, handle: %ld", handle);
-        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "fwrite() error");
+        error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "fwrite() error");
     } else {
         write_data = g_malloc0(sizeof(GuestFileWrite));
         write_data->count = write_count;
@@ -270,14 +270,14 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
     int ret;
 
     if (!gfh) {
-        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
+        error_set(err, QERR_FD_NOT_FOUND, "File descriptor named 'name=%s' not found",  "handle");
         return NULL;
     }
 
     fh = gfh->fh;
     ret = fseek(fh, offset, whence);
     if (ret == -1) {
-        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", strerror(errno));
+        error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  strerror(errno));
     } else {
         seek_data = g_malloc0(sizeof(GuestFileRead));
         seek_data->position = ftell(fh);
@@ -295,14 +295,14 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
     int ret;
 
     if (!gfh) {
-        error_set(err, /* QERR_FD_NOT_FOUND */ 25, "File descriptor named 'name=%s' not found", "handle");
+        error_set(err, QERR_FD_NOT_FOUND, "File descriptor named 'name=%s' not found",  "handle");
         return;
     }
 
     fh = gfh->fh;
     ret = fflush(fh);
     if (ret == EOF) {
-        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", strerror(errno));
+        error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  strerror(errno));
     }
 }
 
@@ -423,7 +423,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
         if (fd == -1) {
             sprintf(err_msg, "failed to open %s, %s", mount->dirname,
                     strerror(errno));
-            error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+            error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
             goto error;
         }
 
@@ -441,7 +441,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
             if (errno != EOPNOTSUPP) {
                 sprintf(err_msg, "failed to freeze %s, %s",
                         mount->dirname, strerror(errno));
-                error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+                error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
                 close(fd);
                 goto error;
             }
@@ -473,7 +473,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
     QTAILQ_INIT(&mounts);
     ret = build_fs_mount_list(&mounts);
     if (ret) {
-        error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to enumerate filesystems");
+        error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "failed to enumerate filesystems");
         return 0;
     }
 
@@ -558,7 +558,7 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
         if (fd == -1) {
             sprintf(err_msg, "failed to open %s, %s", mount->dirname,
                     strerror(errno));
-            error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+            error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
             goto error;
         }
 
@@ -573,7 +573,7 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
             if (errno != ENOTTY && errno != EOPNOTSUPP) {
                 sprintf(err_msg, "failed to trim %s, %s",
                         mount->dirname, strerror(errno));
-                error_set(err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+                error_set(err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
                 close(fd);
                 goto error;
             }
@@ -656,7 +656,7 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg,
         case SUSPEND_SUPPORTED:
             return;
         case SUSPEND_NOT_SUPPORTED:
-            error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+            error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
             return;
         default:
             goto undef_err;
@@ -664,7 +664,7 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg,
     }
 
 undef_err:
-    error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+    error_set(err, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
 }
 
 static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,
@@ -725,7 +725,7 @@ static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,
     }
 
 exit_err:
-    error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+    error_set(err, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
 }
 
 void qmp_guest_suspend_disk(Error **err)
@@ -783,7 +783,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
     if (getifaddrs(&ifap) < 0) {
         snprintf(err_msg, sizeof(err_msg),
                  "getifaddrs failed: %s", strerror(errno));
-        error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+        error_set(errp, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
         goto error;
     }
 
@@ -821,7 +821,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
             if (sock == -1) {
                 snprintf(err_msg, sizeof(err_msg),
                          "failed to create socket: %s", strerror(errno));
-                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+                error_set(errp, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
                 goto error;
             }
 
@@ -832,7 +832,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
                          "failed to get MAC address of %s: %s",
                          ifa->ifa_name,
                          strerror(errno));
-                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+                error_set(errp, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
                 goto error;
             }
 
@@ -845,7 +845,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
                          (int) mac_addr[4], (int) mac_addr[5]) == -1) {
                 snprintf(err_msg, sizeof(err_msg),
                          "failed to format MAC: %s", strerror(errno));
-                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+                error_set(errp, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
                 goto error;
             }
 
@@ -862,7 +862,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
             if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) {
                 snprintf(err_msg, sizeof(err_msg),
                          "inet_ntop failed : %s", strerror(errno));
-                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+                error_set(errp, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
                 goto error;
             }
 
@@ -884,7 +884,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
             if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) {
                 snprintf(err_msg, sizeof(err_msg),
                          "inet_ntop failed : %s", strerror(errno));
-                error_set(errp, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", err_msg);
+                error_set(errp, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  err_msg);
                 goto error;
             }
 
@@ -937,22 +937,22 @@ error:
 
 void qmp_guest_suspend_disk(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 }
 
 void qmp_guest_suspend_ram(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 }
 
 void qmp_guest_suspend_hybrid(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 }
 
 GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
 {
-    error_set(errp, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(errp, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return NULL;
 }
 
@@ -962,21 +962,21 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
 
 GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 
     return 0;
 }
 
 int64_t qmp_guest_fsfreeze_freeze(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 
     return 0;
 }
 
 int64_t qmp_guest_fsfreeze_thaw(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 
     return 0;
 }
@@ -985,7 +985,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
 #if !defined(CONFIG_FSTRIM)
 void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 
     return;
 }
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d5bd012..f7f7989 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -36,7 +36,7 @@ static void acquire_privilege(const char *name, Error **err)
         TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token))
     {
         if (!LookupPrivilegeValue(NULL, name, &priv.Privileges[0].Luid)) {
-            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "no luid for requested privilege");
+            error_set(&local_err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "no luid for requested privilege");
             goto out;
         }
 
@@ -44,13 +44,13 @@ static void acquire_privilege(const char *name, Error **err)
         priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
         if (!AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0)) {
-            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "unable to acquire requested privilege");
+            error_set(&local_err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "unable to acquire requested privilege");
             goto out;
         }
 
         CloseHandle(token);
     } else {
-        error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to open privilege token");
+        error_set(&local_err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "failed to open privilege token");
     }
 
 out:
@@ -68,7 +68,7 @@ static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque, Error **e
     }
     HANDLE thread = CreateThread(NULL, 0, func, opaque, 0, NULL);
     if (!thread) {
-        error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to dispatch asynchronous command");
+        error_set(&local_err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "failed to dispatch asynchronous command");
         error_propagate(err, local_err);
     }
 }
@@ -86,7 +86,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
     } else if (strcmp(mode, "reboot") == 0) {
         shutdown_flag |= EWX_REBOOT;
     } else {
-        error_set(err, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "mode", "halt|powerdown|reboot");
+        error_set(err, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "mode",  "halt|powerdown|reboot");
         return;
     }
 
@@ -99,45 +99,45 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
 
     if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
         slog("guest-shutdown failed: %d", GetLastError());
-        error_set(err, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+        error_set(err, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
     }
 }
 
 int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return 0;
 }
 
 void qmp_guest_file_close(int64_t handle, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 }
 
 GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
                                    int64_t count, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return 0;
 }
 
 GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
                                      bool has_count, int64_t count, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return 0;
 }
 
 GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
                                    int64_t whence, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return 0;
 }
 
 void qmp_guest_file_flush(int64_t handle, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 }
 
 /*
@@ -145,7 +145,7 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
  */
 GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return 0;
 }
 
@@ -155,7 +155,7 @@ GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
  */
 int64_t qmp_guest_fsfreeze_freeze(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return 0;
 }
 
@@ -164,7 +164,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
  */
 int64_t qmp_guest_fsfreeze_thaw(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return 0;
 }
 
@@ -174,7 +174,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
  */
 void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 
     return;
 }
@@ -194,23 +194,23 @@ static void check_suspend_mode(GuestSuspendMode mode, Error **err)
     }
     ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps));
     if (!GetPwrCapabilities(&sys_pwr_caps)) {
-        error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "failed to determine guest suspend capabilities");
+        error_set(&local_err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "failed to determine guest suspend capabilities");
         goto out;
     }
 
     switch (mode) {
     case GUEST_SUSPEND_MODE_DISK:
         if (!sys_pwr_caps.SystemS4) {
-            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "suspend-to-disk not supported by OS");
+            error_set(&local_err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "suspend-to-disk not supported by OS");
         }
         break;
     case GUEST_SUSPEND_MODE_RAM:
         if (!sys_pwr_caps.SystemS3) {
-            error_set(&local_err, /* QERR_QGA_COMMAND_FAILED */ 53, "Guest agent command failed, error was 'message=%s'", "suspend-to-ram not supported by OS");
+            error_set(&local_err, QERR_QGA_COMMAND_FAILED, "Guest agent command failed,  error was 'message=%s'",  "suspend-to-ram not supported by OS");
         }
         break;
     default:
-        error_set(&local_err, /* QERR_INVALID_PARAMETER_VALUE */ 33, "Parameter 'name=%s' expects expected=%s", "mode", "GuestSuspendMode");
+        error_set(&local_err, QERR_INVALID_PARAMETER_VALUE, "Parameter 'name=%s' expects expected=%s",  "mode",  "GuestSuspendMode");
     }
 
 out:
@@ -262,12 +262,12 @@ void qmp_guest_suspend_ram(Error **err)
 
 void qmp_guest_suspend_hybrid(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
 }
 
 GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **err)
 {
-    error_set(err, /* QERR_UNSUPPORTED */ 68, "this feature or command is not currently supported");
+    error_set(err, QERR_UNSUPPORTED, "this feature or command is not currently supported");
     return NULL;
 }
 
diff --git a/qmp.c b/qmp.c
index 562706f..fce58f9 100644
--- a/qmp.c
+++ b/qmp.c
@@ -108,7 +108,7 @@ void qmp_cpu(int64_t index, Error **errp)
    defined in the VNC subsystem */
 VncInfo *qmp_query_vnc(Error **errp)
 {
-    error_set(errp, /* QERR_FEATURE_DISABLED */ 27, "The feature 'name=%s' is not enabled", "vnc");
+    error_set(errp, QERR_FEATURE_DISABLED, "The feature 'name=%s' is not enabled",  "vnc");
     return NULL;
 };
 #endif
@@ -120,7 +120,7 @@ VncInfo *qmp_query_vnc(Error **errp)
    to be available in the namespace if SPICE is not compiled in */
 SpiceInfo *qmp_query_spice(Error **errp)
 {
-    error_set(errp, /* QERR_COMMAND_NOT_FOUND */ 9, "The command name=%s has not been found", "query-spice");
+    error_set(errp, QERR_COMMAND_NOT_FOUND, "The command name=%s has not been found",  "query-spice");
     return NULL;
 };
 #endif
@@ -135,7 +135,7 @@ static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
     Error **err = opaque;
 
     if (!error_is_set(err) && bdrv_key_required(bs)) {
-        error_set(err, /* QERR_DEVICE_ENCRYPTED */ 10, "Device 'device=%s' is encrypted (filename=filename=%s)", bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs));
+        error_set(err, QERR_DEVICE_ENCRYPTED, "Device 'device=%s' is encrypted (filename=filename=%s)",  bdrv_get_device_name(bs),  bdrv_get_encrypted_filename(bs));
     }
 }
 
@@ -144,11 +144,11 @@ void qmp_cont(Error **errp)
     Error *local_err = NULL;
 
     if (runstate_check(RUN_STATE_INMIGRATE)) {
-        error_set(errp, /* QERR_MIGRATION_EXPECTED */ 40, "An incoming migration is expected before this command can be executed");
+        error_set(errp, QERR_MIGRATION_EXPECTED, "An incoming migration is expected before this command can be executed");
         return;
     } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
                runstate_check(RUN_STATE_SHUTDOWN)) {
-        error_set(errp, /* QERR_RESET_REQUIRED */ 58, "Resetting the Virtual Machine is required");
+        error_set(errp, QERR_RESET_REQUIRED, "Resetting the Virtual Machine is required");
         return;
     } else if (runstate_check(RUN_STATE_SUSPENDED)) {
         return;
@@ -178,7 +178,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
 
     obj = object_resolve_path(path, &ambiguous);
     if (obj == NULL) {
-        error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
+        error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  path);
         return NULL;
     }
 
@@ -207,7 +207,7 @@ int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
 
     obj = object_resolve_path(path, NULL);
     if (!obj) {
-        error_set(&local_err, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
+        error_set(&local_err, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  path);
         goto out;
     }
 
@@ -232,7 +232,7 @@ int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
 
     obj = object_resolve_path(path, NULL);
     if (!obj) {
-        error_set(&local_err, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
+        error_set(&local_err, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  path);
         goto out;
     }
 
@@ -263,7 +263,7 @@ void qmp_set_password(const char *protocol, const char *password,
         } else if (strcmp(connected, "keep") == 0) {
             /* nothing */
         } else {
-            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "connected");
+            error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "connected");
             return;
         }
     }
@@ -271,13 +271,13 @@ void qmp_set_password(const char *protocol, const char *password,
     if (strcmp(protocol, "spice") == 0) {
         if (!using_spice) {
             /* correct one? spice isn't a device ,,, */
-            error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
+            error_set(errp, QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  "spice");
             return;
         }
         rc = qemu_spice_set_passwd(password, fail_if_connected,
                                    disconnect_if_connected);
         if (rc != 0) {
-            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
+            error_set(errp, QERR_SET_PASSWD_FAILED, "Could not set password");
         }
         return;
     }
@@ -285,19 +285,19 @@ void qmp_set_password(const char *protocol, const char *password,
     if (strcmp(protocol, "vnc") == 0) {
         if (fail_if_connected || disconnect_if_connected) {
             /* vnc supports "connected=keep" only */
-            error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "connected");
+            error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "connected");
             return;
         }
         /* Note that setting an empty password will not disable login through
          * this interface. */
         rc = vnc_display_password(NULL, password);
         if (rc < 0) {
-            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
+            error_set(errp, QERR_SET_PASSWD_FAILED, "Could not set password");
         }
         return;
     }
 
-    error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
+    error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "protocol");
 }
 
 void qmp_expire_password(const char *protocol, const char *whenstr,
@@ -319,12 +319,12 @@ void qmp_expire_password(const char *protocol, const char *whenstr,
     if (strcmp(protocol, "spice") == 0) {
         if (!using_spice) {
             /* correct one? spice isn't a device ,,, */
-            error_set(errp, /* QERR_DEVICE_NOT_ACTIVE */ 20, "Device 'device=%s' has not been activated", "spice");
+            error_set(errp, QERR_DEVICE_NOT_ACTIVE, "Device 'device=%s' has not been activated",  "spice");
             return;
         }
         rc = qemu_spice_set_pw_expire(when);
         if (rc != 0) {
-            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
+            error_set(errp, QERR_SET_PASSWD_FAILED, "Could not set password");
         }
         return;
     }
@@ -332,26 +332,26 @@ void qmp_expire_password(const char *protocol, const char *whenstr,
     if (strcmp(protocol, "vnc") == 0) {
         rc = vnc_display_pw_expire(NULL, when);
         if (rc != 0) {
-            error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
+            error_set(errp, QERR_SET_PASSWD_FAILED, "Could not set password");
         }
         return;
     }
 
-    error_set(errp, /* QERR_INVALID_PARAMETER */ 30, "Invalid parameter 'name=%s'", "protocol");
+    error_set(errp, QERR_INVALID_PARAMETER, "Invalid parameter 'name=%s'",  "protocol");
 }
 
 #ifdef CONFIG_VNC
 void qmp_change_vnc_password(const char *password, Error **errp)
 {
     if (vnc_display_password(NULL, password) < 0) {
-        error_set(errp, /* QERR_SET_PASSWD_FAILED */ 59, "Could not set password");
+        error_set(errp, QERR_SET_PASSWD_FAILED, "Could not set password");
     }
 }
 
 static void qmp_change_vnc_listen(const char *target, Error **err)
 {
     if (vnc_display_open(NULL, target) < 0) {
-        error_set(err, /* QERR_VNC_SERVER_FAILED */ 70, "Could not start VNC server on target=%s", target);
+        error_set(err, QERR_VNC_SERVER_FAILED, "Could not start VNC server on target=%s",  target);
     }
 }
 
@@ -360,7 +360,7 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
 {
     if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
         if (!has_arg) {
-            error_set(errp, /* QERR_MISSING_PARAMETER */ 42, "Parameter 'name=%s' is missing", "password");
+            error_set(errp, QERR_MISSING_PARAMETER, "Parameter 'name=%s' is missing",  "password");
         } else {
             qmp_change_vnc_password(arg, errp);
         }
@@ -371,12 +371,12 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
 #else
 void qmp_change_vnc_password(const char *password, Error **errp)
 {
-    error_set(errp, /* QERR_FEATURE_DISABLED */ 27, "The feature 'name=%s' is not enabled", "vnc");
+    error_set(errp, QERR_FEATURE_DISABLED, "The feature 'name=%s' is not enabled",  "vnc");
 }
 static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
                            Error **errp)
 {
-    error_set(errp, /* QERR_FEATURE_DISABLED */ 27, "The feature 'name=%s' is not enabled", "vnc");
+    error_set(errp, QERR_FEATURE_DISABLED, "The feature 'name=%s' is not enabled",  "vnc");
 }
 #endif /* !CONFIG_VNC */
 
diff --git a/qom/object.c b/qom/object.c
index 21b7dba..6ea7dae 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -683,7 +683,7 @@ ObjectProperty *object_property_find(Object *obj, const char *name,
         }
     }
 
-    error_set(errp, /* QERR_PROPERTY_NOT_FOUND */ 47, "Property 'device=%s.property=%s' not found", "", name);
+    error_set(errp, QERR_PROPERTY_NOT_FOUND, "Property 'device=%s.property=%s' not found",  "",  name);
     return NULL;
 }
 
@@ -714,7 +714,7 @@ void object_property_get(Object *obj, Visitor *v, const char *name,
     }
 
     if (!prop->get) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
     } else {
         prop->get(obj, v, prop->opaque, name, errp);
     }
@@ -729,7 +729,7 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
     }
 
     if (!prop->set) {
-        error_set(errp, /* QERR_PERMISSION_DENIED */ 46, "Insufficient permission to perform this operation");
+        error_set(errp, QERR_PERMISSION_DENIED, "Insufficient permission to perform this operation");
     } else {
         prop->set(obj, v, prop->opaque, name, errp);
     }
@@ -756,7 +756,7 @@ char *object_property_get_str(Object *obj, const char *name,
     }
     qstring = qobject_to_qstring(ret);
     if (!qstring) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, "string");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name,  "string");
         retval = NULL;
     } else {
         retval = g_strdup(qstring_get_str(qstring));
@@ -782,7 +782,7 @@ Object *object_property_get_link(Object *obj, const char *name,
     if (str && *str) {
         target = object_resolve_path(str, NULL);
         if (!target) {
-            error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", str);
+            error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  str);
         }
     }
 
@@ -811,7 +811,7 @@ bool object_property_get_bool(Object *obj, const char *name,
     }
     qbool = qobject_to_qbool(ret);
     if (!qbool) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, "boolean");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name,  "boolean");
         retval = false;
     } else {
         retval = qbool_get_int(qbool);
@@ -842,7 +842,7 @@ int64_t object_property_get_int(Object *obj, const char *name,
     }
     qint = qobject_to_qint(ret);
     if (!qint) {
-        error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, "int");
+        error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name,  "int");
         retval = -1;
     } else {
         retval = qint_get_int(qint);
@@ -979,16 +979,16 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
         target = object_resolve_path_type(path, target_type, &ambiguous);
 
         if (ambiguous) {
-            error_set(errp, /* QERR_AMBIGUOUS_PATH */ 1, "Path 'path=%s' does not uniquely identify an object", path);
+            error_set(errp, QERR_AMBIGUOUS_PATH, "Path 'path=%s' does not uniquely identify an object",  path);
         } else if (target) {
             object_ref(target);
             *child = target;
         } else {
             target = object_resolve_path(path, &ambiguous);
             if (target || ambiguous) {
-                error_set(errp, /* QERR_INVALID_PARAMETER_TYPE */ 32, "Invalid parameter type for 'name=%s', expected: expected=%s", name, target_type);
+                error_set(errp, QERR_INVALID_PARAMETER_TYPE, "Invalid parameter type for 'name=%s',  expected: expected=%s",  name,  target_type);
             } else {
-                error_set(errp, /* QERR_DEVICE_NOT_FOUND */ 22, "Device 'device=%s' not found", path);
+                error_set(errp, QERR_DEVICE_NOT_FOUND, "Device 'device=%s' not found",  path);
             }
         }
         g_free(target_type);
diff --git a/savevm.c b/savevm.c
index 71ae5a7..495e0a7 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1555,7 +1555,7 @@ bool qemu_savevm_state_blocked(Error **errp)
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         if (se->no_migrate) {
-            error_set(errp, /* QERR_MIGRATION_NOT_SUPPORTED */ 41, "State blocked by non-migratable device 'device=%s'", se->idstr);
+            error_set(errp, QERR_MIGRATION_NOT_SUPPORTED, "State blocked by non-migratable device 'device=%s'",  se->idstr);
             return true;
         }
     }
@@ -2182,13 +2182,13 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp)
 
     f = qemu_fopen(filename, "wb");
     if (!f) {
-        error_set(errp, /* QERR_OPEN_FILE_FAILED */ 45, "Could not open 'filename=%s'", filename);
+        error_set(errp, QERR_OPEN_FILE_FAILED, "Could not open 'filename=%s'",  filename);
         goto the_end;
     }
     ret = qemu_save_device_state(f);
     qemu_fclose(f);
     if (ret < 0) {
-        error_set(errp, /* QERR_IO_ERROR */ 35, "An IO error has occurred");
+        error_set(errp, QERR_IO_ERROR, "An IO error has occurred");
     }
 
  the_end:
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 7da4dfc..6009bb8 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -631,7 +631,7 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64",  maximum: max=%"PRId64")",  "",  name ? name : "null",  value,  min,  max);
         return;
     }
 
@@ -669,7 +669,7 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64",  maximum: max=%"PRId64")",  "",  name ? name : "null",  value,  min,  max);
         return;
     }
 
@@ -704,7 +704,7 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64",  maximum: max=%"PRId64")",  "",  name ? name : "null",  value,  min,  max);
         return;
     }
 
@@ -769,7 +769,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value,
     int i;
 
     if (strlen(value) != 12) {
-        error_set(errp, /* QERR_PROPERTY_VALUE_BAD */ 48, "Property 'device=%s.property=%s' doesn't take value 'value=%s'", "", "vendor", value);
+        error_set(errp, QERR_PROPERTY_VALUE_BAD, "Property 'device=%s.property=%s' doesn't take value 'value=%s'",  "",  "vendor",  value);
         return;
     }
 
@@ -844,7 +844,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
         return;
     }
     if (value < min || value > max) {
-        error_set(errp, /* QERR_PROPERTY_VALUE_OUT_OF_RANGE */ 52, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64", maximum: max=%"PRId64")", "", name ? name : "null", value, min, max);
+        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "Property 'device=%s.property=%s' doesn't take value value=%"PRId64" (minimum: min=%"PRId64",  maximum: max=%"PRId64")",  "",  name ? name : "null",  value,  min,  max);
         return;
     }
 
diff --git a/ui/vnc.c b/ui/vnc.c
index c448f09..f622d81 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -373,7 +373,7 @@ VncInfo *qmp_query_vnc(Error **errp)
 
         if (getsockname(vnc_display->lsock, (struct sockaddr *)&sa,
                         &salen) == -1) {
-            error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+            error_set(errp, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
             goto out_error;
         }
 
@@ -381,7 +381,7 @@ VncInfo *qmp_query_vnc(Error **errp)
                         host, sizeof(host),
                         serv, sizeof(serv),
                         NI_NUMERICHOST | NI_NUMERICSERV) < 0) {
-            error_set(errp, /* QERR_UNDEFINED_ERROR */ 66, "An undefined error has occurred");
+            error_set(errp, QERR_UNDEFINED_ERROR, "An undefined error has occurred");
             goto out_error;
         }
 
-- 
1.7.11.2.249.g31c7954.dirty

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (13 preceding siblings ...)
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 14/14] error: change all error_set() " Luiz Capitulino
@ 2012-07-26  2:43 ` Anthony Liguori
  2012-07-26  9:45   ` Kevin Wolf
  2012-07-26 16:12   ` Daniel P. Berrange
  2012-07-26 15:54 ` Markus Armbruster
  15 siblings, 2 replies; 37+ messages in thread
From: Anthony Liguori @ 2012-07-26  2:43 UTC (permalink / raw)
  To: Luiz Capitulino, qemu-devel; +Cc: pbonzini, armbru, afaerber, peter.maydell

Luiz Capitulino <lcapitulino@redhat.com> writes:

> Basically, this series changes a call like:
>
>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>
> to:
>
>  error_set(errp, QERR_DEVICE_NOT_FOUND,
>            "Device 'device=%s' not found", device);
>
> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>
>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"

This is the wrong direction.  Looking through the patch, this makes the
code much more redundant overall.  You have dozens of calls that are
duplicating the same error message.  This is not progress.

We should just stick with a simple QERR_GENERIC and call it a day.
Let's not needlessly complicate existing code.

Regards,

Anthony Liguori

>
> error_set() then uses that string and the 'device' argument to build the
> error object, which is a QDict. The human error message is fixed, and exists
> in the qerror_table[] array. That array is indexed, and the human error
> message is added to the error object.
>
> In the new way, QERR_DEVICE_NOT_FOUND is an enumeration value and the
> human error message is passed as an argument. qerror_table[] is gone. The
> error object is built by using QERR_DEVICE_NOT_FOUND as an index for a table
> containing all those json dict strings (this can, and probably will, be
> eliminated, as the QMP code can generate its error object from the Error
> object).
>
> An important detail is that, the error object data member is constructed
> by parsing the human message string and looking for name=value pairs. If
> a required data member (like 'device' above) is not found in the human message,
> a default value is used ('unknown' for strings and 0 for integers).
>
> This series unlocks several possible simplification, like moving from:
>
>     struct Error
>     {
>         QDict *obj;
>         const char *fmt;
>         char *msg;
>     };
>
> to:
>
>     struct Error
>     {
>         ErrClass err_class;
>         char *msg;
>     };
>
> But I haven't done it all yet.
>
> Please, check individual patches for more details.
>
>  balloon.c                   |  10 +-
>  block.c                     |   4 +-
>  block/cow.c                 |   3 +-
>  block/qcow.c                |   7 +-
>  block/qcow2.c               |   3 +-
>  block/qed.c                 |   3 +-
>  block/stream.c              |   2 +-
>  block/vdi.c                 |   4 +-
>  block/vmdk.c                |   4 +-
>  block/vpc.c                 |   4 +-
>  block/vvfat.c               |   4 +-
>  blockdev.c                  |  79 +++++++-------
>  configure                   |  10 --
>  cpus.c                      |  13 ++-
>  dump-stub.c                 |   2 +-
>  dump.c                      |  18 ++--
>  error.c                     |  45 ++------
>  error.h                     |   5 +-
>  hmp.c                       |   2 +-
>  hw/9pfs/virtio-9p.c         |   3 +-
>  hw/ivshmem.c                |   2 +-
>  hw/pci-stub.c               |   2 +-
>  hw/pci.c                    |   4 +-
>  hw/qdev-addr.c              |   6 +-
>  hw/qdev-monitor.c           |  26 +++--
>  hw/qdev-properties.c        |  49 ++++-----
>  hw/qdev.c                   |   6 +-
>  hw/usb/bus.c                |   3 +-
>  hw/usb/hcd-ehci.c           |   6 +-
>  hw/usb/redirect.c           |   5 +-
>  json-parser.c               |   2 +-
>  migration.c                 |   6 +-
>  monitor.c                   | 127 +++++------------------
>  net.c                       |  20 ++--
>  qapi/qapi-visit-core.c      |  22 ++--
>  qapi/qmp-dispatch.c         |  14 ++-
>  qapi/qmp-input-visitor.c    |  22 ++--
>  qapi/string-input-visitor.c |  12 +--
>  qemu-config.c               |   2 +-
>  qemu-ga.c                   |   4 +-
>  qemu-option.c               |  20 ++--
>  qemu-sockets.c              |  22 ++--
>  qerror.c                    | 243 ++++++++++++++------------------------------
>  qerror.h                    |  22 +---
>  qga/commands-posix.c        |  78 +++++++-------
>  qga/commands-win32.c        |  53 ++++------
>  qmp.c                       |  47 +++++----
>  qom/object.c                |  20 ++--
>  savevm.c                    |   6 +-
>  scripts/qapi-errors.py      |  80 ++++++++-------
>  target-i386/cpu.c           |  15 +--
>  ui/vnc.c                    |   4 +-
>  52 files changed, 450 insertions(+), 725 deletions(-)

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26  2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
@ 2012-07-26  9:45   ` Kevin Wolf
  2012-07-26 12:41     ` Anthony Liguori
  2012-07-26 16:12   ` Daniel P. Berrange
  1 sibling, 1 reply; 37+ messages in thread
From: Kevin Wolf @ 2012-07-26  9:45 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: peter.maydell, qemu-devel, armbru, pbonzini, Luiz Capitulino, afaerber

Am 26.07.2012 04:43, schrieb Anthony Liguori:
> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
>> Basically, this series changes a call like:
>>
>>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>>
>> to:
>>
>>  error_set(errp, QERR_DEVICE_NOT_FOUND,
>>            "Device 'device=%s' not found", device);
>>
>> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>>
>>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
> 
> This is the wrong direction.  Looking through the patch, this makes the
> code much more redundant overall.  You have dozens of calls that are
> duplicating the same error message.  This is not progress.

I believe this is mostly because it's a mechanical conversion. Once this
is done, we can change error messages to better fit the individual cases.

> We should just stick with a simple QERR_GENERIC and call it a day.
> Let's not needlessly complicate existing code.

Why even have error codes when everything should become QERR_GENERIC? Or
am I misunderstanding?

Kevin

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort()
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Luiz Capitulino
@ 2012-07-26 12:33   ` Markus Armbruster
  2012-07-26 15:02     ` Luiz Capitulino
  2012-07-26 12:59   ` Eric Blake
  1 sibling, 1 reply; 37+ messages in thread
From: Markus Armbruster @ 2012-07-26 12:33 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: peter.maydell, pbonzini, aliguori, qemu-devel, afaerber

Luiz Capitulino <lcapitulino@redhat.com> writes:

> Previously, developers had to create error dicts manually and also enter
> the matching desc table entry. Thus, qerro_abort() was added to help

s/qerro_/qerror_/

> catching bad error dicts.
>
> Today, all that stuff is generated automatically which makes the chance
> of a bad generated dict quite low.

The generator can only generate well-formed dicts, right?

> Also, qerror_abort() would... _abort_ on a bad error dict!

In my opinion, it's perfectly fine to abort on a programming error.

> This commit maintains the same verification logic on the error object
> but drops the abort() in favor of reporting UndefinedError for bad dicts
> (and also print a debug message to stderr).

I certainly won't object to your elaborate handling, but me, I'd simply
replace qerror_abort() by straight abort() and be done with it *shrug*

> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  qerror.c | 83 +++++++++++++++++++++++++++++++++++-----------------------------
>  1 file changed, 46 insertions(+), 37 deletions(-)
>
> diff --git a/qerror.c b/qerror.c
> index d428b52..74b3659 100644
> --- a/qerror.c
> +++ b/qerror.c
> @@ -38,55 +38,50 @@ static QError *qerror_new(void)
>      return qerr;
>  }
>  
> -static void GCC_FMT_ATTR(2, 3) qerror_abort(const QError *qerr,
> -                                            const char *fmt, ...)
> -{
> -    va_list ap;
> -
> -    fprintf(stderr, "qerror: bad call in function '%s':\n", qerr->func);
> -    fprintf(stderr, "qerror: -> ");
> -
> -    va_start(ap, fmt);
> -    vfprintf(stderr, fmt, ap);
> -    va_end(ap);
> -
> -    fprintf(stderr, "\nqerror: call at %s:%d\n", qerr->file, qerr->linenr);
> -    abort();
> -}
> -
> -static void GCC_FMT_ATTR(2, 0) qerror_set_data(QError *qerr,
> -                                               const char *fmt, va_list *va)
> +static QDict *error_object_from_fmt(const char *fmt, va_list *va)
>  {
>      QObject *obj;
> +    QDict *ret;
>  
>      obj = qobject_from_jsonv(fmt, va);
>      if (!obj) {
> -        qerror_abort(qerr, "invalid format '%s'", fmt);
> +        fprintf(stderr, "invalid json in error dict '%s'\n", fmt);
> +        return NULL;
>      }
>      if (qobject_type(obj) != QTYPE_QDICT) {
> -        qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
> +        fprintf(stderr, "error is not a dict '%s'\n", fmt);
> +        goto out_free;
>      }
>  
> -    qerr->error = qobject_to_qdict(obj);
> -
> -    obj = qdict_get(qerr->error, "class");
> +    ret = qobject_to_qdict(obj);
> +    obj = qdict_get(ret, "class");
>      if (!obj) {
> -        qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
> +        fprintf(stderr, "missing 'class' key in '%s'\n", fmt);
> +        goto out_free;
>      }
>      if (qobject_type(obj) != QTYPE_QSTRING) {
> -        qerror_abort(qerr, "'class' key value should be a QString");
> +        fprintf(stderr, "'class' key value should be a string in '%s'\n", fmt);
> +        goto out_free;
>      }
> -    
> -    obj = qdict_get(qerr->error, "data");
> +
> +    obj = qdict_get(ret, "data");
>      if (!obj) {
> -        qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
> +        fprintf(stderr, "missing 'data' key in '%s'\n", fmt);
> +        goto out_free;
>      }
>      if (qobject_type(obj) != QTYPE_QDICT) {
> -        qerror_abort(qerr, "'data' key value should be a QDICT");
> +        fprintf(stderr, "'data' key value should be a dict in '%s'\n", fmt);
> +        goto out_free;
>      }
> +
> +    return ret;
> +
> +out_free:
> +    qobject_decref(obj);
> +    return NULL;
>  }
>  
> -static void qerror_set_desc(QError *qerr, const char *fmt)
> +static const QErrorStringTable *error_get_desc(const char *fmt)
>  {
>      int i;
>  
> @@ -94,12 +89,17 @@ static void qerror_set_desc(QError *qerr, const char *fmt)
>  
>      for (i = 0; qerror_table[i].error_fmt; i++) {
>          if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
> -            qerr->entry = &qerror_table[i];
> -            return;
> +            return &qerror_table[i];
>          }
>      }
>  
> -    qerror_abort(qerr, "error format '%s' not found", fmt);
> +    fprintf(stderr, "error format '%s' not found\n", fmt);
> +    return NULL;
> +}
> +
> +static QDict *build_error_no_arg(const char *fmt)
> +{
> +    return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
>  }
>  
>  /**
> @@ -127,13 +127,22 @@ static QError *qerror_from_info(const char *file, int linenr, const char *func,
>      qerr->file = file;
>      qerr->func = func;
>  
> -    if (!fmt) {
> -        qerror_abort(qerr, "QDict not specified");
> +    qerr->error = error_object_from_fmt(fmt, va);
> +    if (!qerr->error) {
> +        goto bad_err;
> +    }
> +
> +    qerr->entry = error_get_desc(fmt);
> +    if (!qerr->entry) {
> +        QDECREF(qerr->error);
> +        goto bad_err;
>      }
>  
> -    qerror_set_data(qerr, fmt, va);
> -    qerror_set_desc(qerr, fmt);
> +    return qerr;
>  
> +bad_err:
> +    qerr->error = build_error_no_arg(QERR_UNDEFINED_ERROR);

Nit: defeats gcc's format checking.  This shouldn't:

       qerr->error = qobject_to_qdict(qobject_from_json(QERR_UNDEFINED_ERROR));

> +    qerr->entry = error_get_desc(QERR_UNDEFINED_ERROR);
>      return qerr;
>  }

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal()
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal() Luiz Capitulino
@ 2012-07-26 12:35   ` Markus Armbruster
  0 siblings, 0 replies; 37+ messages in thread
From: Markus Armbruster @ 2012-07-26 12:35 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: peter.maydell, pbonzini, aliguori, qemu-devel, afaerber

Luiz Capitulino <lcapitulino@redhat.com> writes:

> It's not needed anymore and conflicts with future error improvements.
>
> Also drops related error information, that is, the file where the error
> ocurred, the line number and function. This has never been fully used.

Suggest "Subject: qerror: drop file, linenr, func", because that's the
interesting part.  qerror_report_internal() is merely detail.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26  9:45   ` Kevin Wolf
@ 2012-07-26 12:41     ` Anthony Liguori
  2012-07-26 14:12       ` Luiz Capitulino
  2012-07-26 14:40       ` Kevin Wolf
  0 siblings, 2 replies; 37+ messages in thread
From: Anthony Liguori @ 2012-07-26 12:41 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: peter.maydell, qemu-devel, armbru, pbonzini, Luiz Capitulino, afaerber

Kevin Wolf <kwolf@redhat.com> writes:

> Am 26.07.2012 04:43, schrieb Anthony Liguori:
>> Luiz Capitulino <lcapitulino@redhat.com> writes:
>> 
>>> Basically, this series changes a call like:
>>>
>>>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>>>
>>> to:
>>>
>>>  error_set(errp, QERR_DEVICE_NOT_FOUND,
>>>            "Device 'device=%s' not found", device);
>>>
>>> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>>>
>>>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
>> 
>> This is the wrong direction.  Looking through the patch, this makes the
>> code much more redundant overall.  You have dozens of calls that are
>> duplicating the same error message.  This is not progress.
>
> I believe this is mostly because it's a mechanical conversion. Once this
> is done, we can change error messages to better fit the individual
> cases.

We don't gain anything by touching every user of error and the code gets
more verbose.  If we want to modify an existing error for some good
reason, we can do so my changing error types.

>> We should just stick with a simple QERR_GENERIC and call it a day.
>> Let's not needlessly complicate existing code.
>
> Why even have error codes when everything should become QERR_GENERIC? Or
> am I misunderstanding?

If we want to add an error code, we can do:

   error_set(QERR_GENERIC, "domain", "My free form text")

And then yes, we can change this to:

   error_setf(errp, "domain", "My free form text")

Or pick your favorite short name.

Regards,

Anthony Liguori

>
> Kevin

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[]
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[] Luiz Capitulino
@ 2012-07-26 12:52   ` Markus Armbruster
  0 siblings, 0 replies; 37+ messages in thread
From: Markus Armbruster @ 2012-07-26 12:52 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: peter.maydell, pbonzini, aliguori, qemu-devel, afaerber

Luiz Capitulino <lcapitulino@redhat.com> writes:

> In the near future, the QERR_ macros (which are json strings today) will
> be turned into an enumeration. When we get there, build_error_dict()
> will be used to (guess what) build an error dict by:
>
>  1. Using the error class as an index to error_object_table[], which
>     contains all QMP errors as json strings (with default values)
>
>  2. Use the human error string to construct the error object data member.
>     For example, an error message like:
>
>      "Parameter name=brain has not been found"
>
>      Will construct the following data member:
>
>      'data': { 'name': 'brain' } }
>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  qerror.c               | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  qerror.h               |  1 +
>  scripts/qapi-errors.py | 39 +++++++++++++++++++++++
>  3 files changed, 126 insertions(+)
>
> diff --git a/qerror.c b/qerror.c
> index 42e8687..267545e 100644
> --- a/qerror.c
> +++ b/qerror.c
> @@ -38,6 +38,92 @@ static QError *qerror_new(void)
>      return qerr;
>  }
>  
> +static bool iscchar(int c)
> +{
> +    return (isalpha(c) || isdigit(c) || c == '_');
> +}

Depends on locale, which may not be what you want.

Beware of passing negative arguments to ctype.h functions.

> +
> +static char *get_key(const char *str)
> +{
> +    char *p, *ret;
> +
> +    ret = p = g_strdup(str);
> +
> +    while (!iscchar(*p)) {
> +        p++;
> +    }
> +    memmove(ret, p, strlen(ret));
> +
> +    p = ret;
> +    while (iscchar(*p)) {
> +        p++;
> +    }
> +    *p = '\0';
> +
> +    return ret;
> +}

Suggest something like

static char *get_key(const char *str)
{
    char *beg, *end;

    for (beg = str; !iscchar(*beg); beg++) ;
    for (end = beg; iscchar(*end); end++) ;
    return g_strndup(beg, end - beg);
}

> +
> +static char *get_value(const char *str)
> +{
> +    char *p, *ret;
> +
> +    p = strchr(str, '=');
> +    while (!iscchar(*p)) {
> +        p++;
> +    }
> +    p = ret = g_strdup(p);
> +    while (iscchar(*p)) {
> +        p++;
> +    }
> +    *p = '\0';
> +
> +    return ret;
> +}

Likewise.

> +
> +static void set_dict_data(const char *msg, QDict *data_dict)
> +{
> +    char *str, *msg2, *saveptr = NULL;
> +
> +    msg2 = g_strdup(msg);
> +    str = strtok_r(msg2, " ", &saveptr);
> +    while (str) {
> +        if (strchr(str, '=')) {
> +            char *key = get_key(str);
> +            char *value = get_value(str);
> +
> +            /* FIXME: handle ints */
> +            if (qdict_haskey(data_dict, key)) {
> +                qdict_put(data_dict, key, qstring_from_str(value));
> +            }
> +
> +            g_free(key);
> +            g_free(value);
> +        }
> +        str = strtok_r(NULL, " ", &saveptr);
> +    }
> +
> +    g_free(msg2);
> +}
> +
> +QDict *build_error_dict(int err_class, const char *msg)
> +{
> +    QDict *err_dict;
> +    QObject *obj;
> +
> +    assert(msg[0] != '\0');
> +
> +    obj = qobject_from_json(error_object_table[err_class]);
> +    assert(obj);
> +    assert(qobject_type(obj) == QTYPE_QDICT);
> +
> +    err_dict = qobject_to_qdict(obj);
> +    assert(qdict_haskey(err_dict, "data"));
> +
> +    set_dict_data(msg, qdict_get_qdict(err_dict, "data"));
> +
> +    return err_dict;
> +}
> +
>  static QDict *error_object_from_fmt(const char *fmt, va_list *va)
>  {
>      QObject *obj;
> diff --git a/qerror.h b/qerror.h
> index 16401ff..c4f6053 100644
> --- a/qerror.h
> +++ b/qerror.h
> @@ -36,5 +36,6 @@ void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
>  void qerror_report_err(Error *err);
>  void assert_no_error(Error *err);
>  char *qerror_format(const char *fmt, QDict *error);
> +QDict *build_error_dict(int err_class, const char *msg);
>  
>  #endif /* QERROR_H */
> diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
> index 59cf426..5f8723e 100644
> --- a/scripts/qapi-errors.py
> +++ b/scripts/qapi-errors.py
> @@ -85,6 +85,42 @@ static const QErrorStringTable qerror_table[] = {
>  
>      return ret
>  
> +def gen_error_data_obj(data):
> +    colon = ''
> +    data_str = ''
> +    for k, v in data.items():
> +        data_str += colon + "'%s': " % k
> +        if v == 'str':
> +            data_str += "'unknown'"
> +        elif v == 'int':
> +            data_str += '0'
> +        else:
> +            sys.exit("unknown data type '%s' for error '%s'" % (v, name))
> +        colon = ', '
> +    return data_str

colon is either empty or ', ', but never a colon.  What about calling it
sep, for separator?

> +
> +def gen_error_obj_table(exprs):
> +    ret = mcgen('''
> +static const char *error_object_table[] = {
> +''')
> +
> +    for err in exprs:
> +        data = gen_error_data_obj({})
> +        if err.has_key('data'):
> +            data = gen_error_data_obj(err['data'])
> +        ret += mcgen('''
> +    "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }",
> +''',
> +                error_class=err['error'], error_data=data)
> +
> +    ret += mcgen('''
> +    NULL,
> +};
> +
> +''')
> +
> +    return ret;
> +
>  def gen_error_macro_data_str(data):
>      colon = ''
>      data_str = ''
> @@ -173,5 +209,8 @@ if __name__ == '__main__':
>      ret = gen_error_def_table(exprs)
>      fdef.write(ret)
>  
> +    ret = gen_error_obj_table(exprs)
> +    fdef.write(ret)
> +
>      fdef.flush()
>      fdef.close()

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good Luiz Capitulino
@ 2012-07-26 12:54   ` Markus Armbruster
  0 siblings, 0 replies; 37+ messages in thread
From: Markus Armbruster @ 2012-07-26 12:54 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: peter.maydell, pbonzini, aliguori, qemu-devel, afaerber

Luiz Capitulino <lcapitulino@redhat.com> writes:

> Last commit deprecated it.

Do you mean "Unused since last commit"?

>                            Also drops the code that used it to generate
> error objects.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort()
  2012-07-25 20:50 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Luiz Capitulino
  2012-07-26 12:33   ` Markus Armbruster
@ 2012-07-26 12:59   ` Eric Blake
  1 sibling, 0 replies; 37+ messages in thread
From: Eric Blake @ 2012-07-26 12:59 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: peter.maydell, aliguori, qemu-devel, armbru, pbonzini, afaerber

[-- Attachment #1: Type: text/plain, Size: 812 bytes --]

On 07/25/2012 02:50 PM, Luiz Capitulino wrote:
> Previously, developers had to create error dicts manually and also enter
> the matching desc table entry. Thus, qerro_abort() was added to help

s/qerro_/qerror_/

> catching bad error dicts.
> 
> Today, all that stuff is generated automatically which makes the chance
> of a bad generated dict quite low.
> 
> Also, qerror_abort() would... _abort_ on a bad error dict!
> 
> This commit maintains the same verification logic on the error object
> but drops the abort() in favor of reporting UndefinedError for bad dicts
> (and also print a debug message to stderr).
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 12:41     ` Anthony Liguori
@ 2012-07-26 14:12       ` Luiz Capitulino
  2012-07-26 15:05         ` Anthony Liguori
  2012-07-26 14:40       ` Kevin Wolf
  1 sibling, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-26 14:12 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Kevin Wolf, peter.maydell, qemu-devel, armbru, pbonzini, afaerber

On Thu, 26 Jul 2012 07:41:07 -0500
Anthony Liguori <aliguori@us.ibm.com> wrote:

> Kevin Wolf <kwolf@redhat.com> writes:
> 
> > Am 26.07.2012 04:43, schrieb Anthony Liguori:
> >> Luiz Capitulino <lcapitulino@redhat.com> writes:
> >> 
> >>> Basically, this series changes a call like:
> >>>
> >>>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> >>>
> >>> to:
> >>>
> >>>  error_set(errp, QERR_DEVICE_NOT_FOUND,
> >>>            "Device 'device=%s' not found", device);
> >>>
> >>> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
> >>>
> >>>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
> >> 
> >> This is the wrong direction.  Looking through the patch, this makes the
> >> code much more redundant overall.  You have dozens of calls that are
> >> duplicating the same error message.  This is not progress.
> >
> > I believe this is mostly because it's a mechanical conversion. Once this
> > is done, we can change error messages to better fit the individual
> > cases.

Correct.

> 
> We don't gain anything by touching every user of error and the code gets
> more verbose. 

We do gain the possibility to have better and different human messages for the
same error class. That's impossible today. And creating a different error class
just to have a different error message is just crazy (which is what we do
today, btw).

Now, if the problem you see is that we shouldn't touch current users but
add a new function for new users to use (or change old users incrementally, when
it matters), then we can discuss that.

> If we want to modify an existing error for some good
> reason, we can do so my changing error types.

You mean, creating a new error class just to have a different human message?
We have 70+ classes today, how many will we have in another year?

> 
> >> We should just stick with a simple QERR_GENERIC and call it a day.
> >> Let's not needlessly complicate existing code.
> >
> > Why even have error codes when everything should become QERR_GENERIC? Or
> > am I misunderstanding?
> 
> If we want to add an error code, we can do:
> 
>    error_set(QERR_GENERIC, "domain", "My free form text")
> 
> And then yes, we can change this to:
> 
>    error_setf(errp, "domain", "My free form text")

Would domain be the error classes we have today?

If error_setf() ends result is similar to what this series does with
error_set(), then that might be acceptable, although I fear we keep
adding new ways to report errors.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 12:41     ` Anthony Liguori
  2012-07-26 14:12       ` Luiz Capitulino
@ 2012-07-26 14:40       ` Kevin Wolf
  2012-07-26 15:20         ` Anthony Liguori
  1 sibling, 1 reply; 37+ messages in thread
From: Kevin Wolf @ 2012-07-26 14:40 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: peter.maydell, armbru, qemu-devel, Luiz Capitulino, pbonzini, afaerber

Am 26.07.2012 14:41, schrieb Anthony Liguori:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
>> Am 26.07.2012 04:43, schrieb Anthony Liguori:
>>> Luiz Capitulino <lcapitulino@redhat.com> writes:
>>>
>>>> Basically, this series changes a call like:
>>>>
>>>>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>>>>
>>>> to:
>>>>
>>>>  error_set(errp, QERR_DEVICE_NOT_FOUND,
>>>>            "Device 'device=%s' not found", device);
>>>>
>>>> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>>>>
>>>>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
>>>
>>> This is the wrong direction.  Looking through the patch, this makes the
>>> code much more redundant overall.  You have dozens of calls that are
>>> duplicating the same error message.  This is not progress.
>>
>> I believe this is mostly because it's a mechanical conversion. Once this
>> is done, we can change error messages to better fit the individual
>> cases.
> 
> We don't gain anything by touching every user of error and the code gets
> more verbose.  If we want to modify an existing error for some good
> reason, we can do so my changing error types.

We gain consistency instead of accumulating the relics of even more
halfway completed direction changes.

>>> We should just stick with a simple QERR_GENERIC and call it a day.
>>> Let's not needlessly complicate existing code.
>>
>> Why even have error codes when everything should become QERR_GENERIC? Or
>> am I misunderstanding?
> 
> If we want to add an error code, we can do:
> 
>    error_set(QERR_GENERIC, "domain", "My free form text")
> 
> And then yes, we can change this to:
> 
>    error_setf(errp, "domain", "My free form text")
> 
> Or pick your favorite short name.

You mentioned this domain thing before, and when asked you never
explained what you really mean with it. Can you do so now, please?

Assuming that it's just some error class string, I don't really see the
difference between error_set(QERR_FOO, "Free form") as implemented by
this series and error_set(QERR_GENERIC, "FOO", "Free form").

Kevin

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort()
  2012-07-26 12:33   ` Markus Armbruster
@ 2012-07-26 15:02     ` Luiz Capitulino
  0 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-26 15:02 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: peter.maydell, pbonzini, aliguori, qemu-devel, afaerber

On Thu, 26 Jul 2012 14:33:23 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > Previously, developers had to create error dicts manually and also enter
> > the matching desc table entry. Thus, qerro_abort() was added to help
> 
> s/qerro_/qerror_/
> 
> > catching bad error dicts.
> >
> > Today, all that stuff is generated automatically which makes the chance
> > of a bad generated dict quite low.
> 
> The generator can only generate well-formed dicts, right?

I didn't say that. I said the chances of generating a bad dict is low,
specially in production.

> 
> > Also, qerror_abort() would... _abort_ on a bad error dict!
> 
> In my opinion, it's perfectly fine to abort on a programming error.

In this case it's quite easy to recover, so why should we abort?

> 
> > This commit maintains the same verification logic on the error object
> > but drops the abort() in favor of reporting UndefinedError for bad dicts
> > (and also print a debug message to stderr).
> 
> I certainly won't object to your elaborate handling, but me, I'd simply
> replace qerror_abort() by straight abort() and be done with it *shrug*

Well, honestly speaking, I did this while I was re-reading that code and
I ended up dropping it down this series (remember this is an RFC) :)

But I think I'll add it back for v1.

> 
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> >  qerror.c | 83 +++++++++++++++++++++++++++++++++++-----------------------------
> >  1 file changed, 46 insertions(+), 37 deletions(-)
> >
> > diff --git a/qerror.c b/qerror.c
> > index d428b52..74b3659 100644
> > --- a/qerror.c
> > +++ b/qerror.c
> > @@ -38,55 +38,50 @@ static QError *qerror_new(void)
> >      return qerr;
> >  }
> >  
> > -static void GCC_FMT_ATTR(2, 3) qerror_abort(const QError *qerr,
> > -                                            const char *fmt, ...)
> > -{
> > -    va_list ap;
> > -
> > -    fprintf(stderr, "qerror: bad call in function '%s':\n", qerr->func);
> > -    fprintf(stderr, "qerror: -> ");
> > -
> > -    va_start(ap, fmt);
> > -    vfprintf(stderr, fmt, ap);
> > -    va_end(ap);
> > -
> > -    fprintf(stderr, "\nqerror: call at %s:%d\n", qerr->file, qerr->linenr);
> > -    abort();
> > -}
> > -
> > -static void GCC_FMT_ATTR(2, 0) qerror_set_data(QError *qerr,
> > -                                               const char *fmt, va_list *va)
> > +static QDict *error_object_from_fmt(const char *fmt, va_list *va)
> >  {
> >      QObject *obj;
> > +    QDict *ret;
> >  
> >      obj = qobject_from_jsonv(fmt, va);
> >      if (!obj) {
> > -        qerror_abort(qerr, "invalid format '%s'", fmt);
> > +        fprintf(stderr, "invalid json in error dict '%s'\n", fmt);
> > +        return NULL;
> >      }
> >      if (qobject_type(obj) != QTYPE_QDICT) {
> > -        qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
> > +        fprintf(stderr, "error is not a dict '%s'\n", fmt);
> > +        goto out_free;
> >      }
> >  
> > -    qerr->error = qobject_to_qdict(obj);
> > -
> > -    obj = qdict_get(qerr->error, "class");
> > +    ret = qobject_to_qdict(obj);
> > +    obj = qdict_get(ret, "class");
> >      if (!obj) {
> > -        qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
> > +        fprintf(stderr, "missing 'class' key in '%s'\n", fmt);
> > +        goto out_free;
> >      }
> >      if (qobject_type(obj) != QTYPE_QSTRING) {
> > -        qerror_abort(qerr, "'class' key value should be a QString");
> > +        fprintf(stderr, "'class' key value should be a string in '%s'\n", fmt);
> > +        goto out_free;
> >      }
> > -    
> > -    obj = qdict_get(qerr->error, "data");
> > +
> > +    obj = qdict_get(ret, "data");
> >      if (!obj) {
> > -        qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
> > +        fprintf(stderr, "missing 'data' key in '%s'\n", fmt);
> > +        goto out_free;
> >      }
> >      if (qobject_type(obj) != QTYPE_QDICT) {
> > -        qerror_abort(qerr, "'data' key value should be a QDICT");
> > +        fprintf(stderr, "'data' key value should be a dict in '%s'\n", fmt);
> > +        goto out_free;
> >      }
> > +
> > +    return ret;
> > +
> > +out_free:
> > +    qobject_decref(obj);
> > +    return NULL;
> >  }
> >  
> > -static void qerror_set_desc(QError *qerr, const char *fmt)
> > +static const QErrorStringTable *error_get_desc(const char *fmt)
> >  {
> >      int i;
> >  
> > @@ -94,12 +89,17 @@ static void qerror_set_desc(QError *qerr, const char *fmt)
> >  
> >      for (i = 0; qerror_table[i].error_fmt; i++) {
> >          if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
> > -            qerr->entry = &qerror_table[i];
> > -            return;
> > +            return &qerror_table[i];
> >          }
> >      }
> >  
> > -    qerror_abort(qerr, "error format '%s' not found", fmt);
> > +    fprintf(stderr, "error format '%s' not found\n", fmt);
> > +    return NULL;
> > +}
> > +
> > +static QDict *build_error_no_arg(const char *fmt)
> > +{
> > +    return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
> >  }
> >  
> >  /**
> > @@ -127,13 +127,22 @@ static QError *qerror_from_info(const char *file, int linenr, const char *func,
> >      qerr->file = file;
> >      qerr->func = func;
> >  
> > -    if (!fmt) {
> > -        qerror_abort(qerr, "QDict not specified");
> > +    qerr->error = error_object_from_fmt(fmt, va);
> > +    if (!qerr->error) {
> > +        goto bad_err;
> > +    }
> > +
> > +    qerr->entry = error_get_desc(fmt);
> > +    if (!qerr->entry) {
> > +        QDECREF(qerr->error);
> > +        goto bad_err;
> >      }
> >  
> > -    qerror_set_data(qerr, fmt, va);
> > -    qerror_set_desc(qerr, fmt);
> > +    return qerr;
> >  
> > +bad_err:
> > +    qerr->error = build_error_no_arg(QERR_UNDEFINED_ERROR);
> 
> Nit: defeats gcc's format checking.  This shouldn't:
> 
>        qerr->error = qobject_to_qdict(qobject_from_json(QERR_UNDEFINED_ERROR));
> 
> > +    qerr->entry = error_get_desc(QERR_UNDEFINED_ERROR);
> >      return qerr;
> >  }
> 

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 14:12       ` Luiz Capitulino
@ 2012-07-26 15:05         ` Anthony Liguori
  2012-07-26 15:52           ` Markus Armbruster
  0 siblings, 1 reply; 37+ messages in thread
From: Anthony Liguori @ 2012-07-26 15:05 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: Kevin Wolf, peter.maydell, qemu-devel, armbru, pbonzini, afaerber

Luiz Capitulino <lcapitulino@redhat.com> writes:

> On Thu, 26 Jul 2012 07:41:07 -0500
> Anthony Liguori <aliguori@us.ibm.com> wrote:
>
>> Kevin Wolf <kwolf@redhat.com> writes:
>> 
>> > Am 26.07.2012 04:43, schrieb Anthony Liguori:
>> >> Luiz Capitulino <lcapitulino@redhat.com> writes:
>> >> 
>> >>> Basically, this series changes a call like:
>> >>>
>> >>>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>> >>>
>> >>> to:
>> >>>
>> >>>  error_set(errp, QERR_DEVICE_NOT_FOUND,
>> >>>            "Device 'device=%s' not found", device);
>> >>>
>> >>> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>> >>>
>> >>>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
>> >> 
>> >> This is the wrong direction.  Looking through the patch, this makes the
>> >> code much more redundant overall.  You have dozens of calls that are
>> >> duplicating the same error message.  This is not progress.
>> >
>> > I believe this is mostly because it's a mechanical conversion. Once this
>> > is done, we can change error messages to better fit the individual
>> > cases.
>
> Correct.
>
>> 
>> We don't gain anything by touching every user of error and the code gets
>> more verbose. 
>
> We do gain the possibility to have better and different human messages for the
> same error class. That's impossible today. And creating a different error class
> just to have a different error message is just crazy (which is what we do
> today, btw).
>
> Now, if the problem you see is that we shouldn't touch current users but
> add a new function for new users to use (or change old users incrementally, when
> it matters), then we can discuss that.

Yup, that's what I've been saying.

>
>> If we want to modify an existing error for some good
>> reason, we can do so my changing error types.
>
> You mean, creating a new error class just to have a different human message?
> We have 70+ classes today, how many will we have in another year?

"changing error types" -> to use the new QERR_GENERIC one.

>> >> We should just stick with a simple QERR_GENERIC and call it a day.
>> >> Let's not needlessly complicate existing code.
>> >
>> > Why even have error codes when everything should become QERR_GENERIC? Or
>> > am I misunderstanding?
>> 
>> If we want to add an error code, we can do:
>> 
>>    error_set(QERR_GENERIC, "domain", "My free form text")
>> 
>> And then yes, we can change this to:
>> 
>>    error_setf(errp, "domain", "My free form text")
>
> Would domain be the error classes we have today?

I'd be perfectly content with letting domain be a free form text that's
managed by the subsystem and not centrally defined.  If we also stick:

error_setf(errp, "domain", int_code, "My free form text")

Then we're GError compatible.  If we throw away our existing error
infrastructure and incrementally adopt GError, then that excites me :-)

> If error_setf() ends result is similar to what this series does with
> error_set(), then that might be acceptable, although I fear we keep
> adding new ways to report errors.

I think having an end goal of using GError is a good way to avoid the
never ending cycle of inventing a better mouse trap.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 14:40       ` Kevin Wolf
@ 2012-07-26 15:20         ` Anthony Liguori
  0 siblings, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2012-07-26 15:20 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: peter.maydell, armbru, qemu-devel, Luiz Capitulino, pbonzini, afaerber

Kevin Wolf <kwolf@redhat.com> writes:

> Am 26.07.2012 14:41, schrieb Anthony Liguori:
>> Kevin Wolf <kwolf@redhat.com> writes:
>> 
>>> Am 26.07.2012 04:43, schrieb Anthony Liguori:
>>>> Luiz Capitulino <lcapitulino@redhat.com> writes:
>>>>
>>>>> Basically, this series changes a call like:
>>>>>
>>>>>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>>>>>
>>>>> to:
>>>>>
>>>>>  error_set(errp, QERR_DEVICE_NOT_FOUND,
>>>>>            "Device 'device=%s' not found", device);
>>>>>
>>>>> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>>>>>
>>>>>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
>>>>
>>>> This is the wrong direction.  Looking through the patch, this makes the
>>>> code much more redundant overall.  You have dozens of calls that are
>>>> duplicating the same error message.  This is not progress.
>>>
>>> I believe this is mostly because it's a mechanical conversion. Once this
>>> is done, we can change error messages to better fit the individual
>>> cases.
>> 
>> We don't gain anything by touching every user of error and the code gets
>> more verbose.  If we want to modify an existing error for some good
>> reason, we can do so my changing error types.
>
> We gain consistency instead of accumulating the relics of even more
> halfway completed direction changes.

Sorry, but taking the "Device 'device=%s' not found" string and
replicating a dozen times is not helpful at all.  Having a single method
to generate device not found errors is a Good Thing.  Could it be a
function around a string instead of JSON magic?  Sure.  But open coding
is not a step forward.

>>>> We should just stick with a simple QERR_GENERIC and call it a day.
>>>> Let's not needlessly complicate existing code.
>>>
>>> Why even have error codes when everything should become QERR_GENERIC? Or
>>> am I misunderstanding?
>> 
>> If we want to add an error code, we can do:
>> 
>>    error_set(QERR_GENERIC, "domain", "My free form text")
>> 
>> And then yes, we can change this to:
>> 
>>    error_setf(errp, "domain", "My free form text")
>> 
>> Or pick your favorite short name.
>
> You mentioned this domain thing before, and when asked you never
> explained what you really mean with it. Can you do so now, please?

http://developer.gnome.org/glib/stable/glib-Error-Reporting.html

In terms of GError, domain is a unique string which defines the meaning
of the error codes.  Most often, domain is either a library and/or
module name.

So we would probably have a "qcow2" domain and a "block" domain to
differientiate errors generated from qcow2 vs. the generic block layer.

> Assuming that it's just some error class string, I don't really see the
> difference between error_set(QERR_FOO, "Free form") as implemented by
> this series and error_set(QERR_GENERIC, "FOO", "Free form").

I don't care about using free strings vs. #defines.  I care about open
coding strings that ought to be common and consistent.

Regards,

Anthony Liguori

>
> Kevin

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 15:05         ` Anthony Liguori
@ 2012-07-26 15:52           ` Markus Armbruster
  0 siblings, 0 replies; 37+ messages in thread
From: Markus Armbruster @ 2012-07-26 15:52 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Kevin Wolf, peter.maydell, qemu-devel, Luiz Capitulino, pbonzini,
	afaerber

Anthony Liguori <aliguori@us.ibm.com> writes:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
>
>> On Thu, 26 Jul 2012 07:41:07 -0500
>> Anthony Liguori <aliguori@us.ibm.com> wrote:
>>
>>> Kevin Wolf <kwolf@redhat.com> writes:
>>> 
>>> > Am 26.07.2012 04:43, schrieb Anthony Liguori:
>>> >> Luiz Capitulino <lcapitulino@redhat.com> writes:
>>> >> 
>>> >>> Basically, this series changes a call like:
>>> >>>
>>> >>>  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>>> >>>
>>> >>> to:
>>> >>>
>>> >>>  error_set(errp, QERR_DEVICE_NOT_FOUND,
>>> >>>            "Device 'device=%s' not found", device);
>>> >>>
>>> >>> In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>>> >>>
>>> >>>     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
>>> >> 
>>> >> This is the wrong direction.  Looking through the patch, this makes the
>>> >> code much more redundant overall.  You have dozens of calls that are
>>> >> duplicating the same error message.  This is not progress.
>>> >
>>> > I believe this is mostly because it's a mechanical conversion. Once this
>>> > is done, we can change error messages to better fit the individual
>>> > cases.
>>
>> Correct.
>>
>>> 
>>> We don't gain anything by touching every user of error and the code gets
>>> more verbose. 

Of the 71 error types, two are unused, and 31 are used exactly once.
For these 33, the code gets *less* verbose.  For the 29 used twice or
thrice, it's a wash.

Any added "verbosity" is a *feature*.  It corrects the design mistake of
factoring out the human-readable messages.  "One size fits all
human-readable error message" is an anti-feature.

>> We do gain the possibility to have better and different human messages for the
>> same error class. That's impossible today. And creating a different
>> error class
>> just to have a different error message is just crazy (which is what we do
>> today, btw).
>>
>> Now, if the problem you see is that we shouldn't touch current users but
>> add a new function for new users to use (or change old users
>> incrementally, when
>> it matters), then we can discuss that.
>
> Yup, that's what I've been saying.

I count four error reporting mechanisms in wide use:

1. ad hoc prints

2. error_report()

3. qerror_report()

4. error_set()

Are you seriously proposing to add a new one that doesn't replace any of
the old ones?

There's no shame in getting yourself into a hole once in a while, only
in continuing to dig.

>>> If we want to modify an existing error for some good
>>> reason, we can do so my changing error types.
>>
>> You mean, creating a new error class just to have a different human message?
>> We have 70+ classes today, how many will we have in another year?
>
> "changing error types" -> to use the new QERR_GENERIC one.
>
>>> >> We should just stick with a simple QERR_GENERIC and call it a day.
>>> >> Let's not needlessly complicate existing code.
>>> >
>>> > Why even have error codes when everything should become QERR_GENERIC? Or
>>> > am I misunderstanding?
>>> 
>>> If we want to add an error code, we can do:
>>> 
>>>    error_set(QERR_GENERIC, "domain", "My free form text")
>>> 
>>> And then yes, we can change this to:
>>> 
>>>    error_setf(errp, "domain", "My free form text")
>>
>> Would domain be the error classes we have today?
>
> I'd be perfectly content with letting domain be a free form text that's
> managed by the subsystem and not centrally defined.  If we also stick:
>
> error_setf(errp, "domain", int_code, "My free form text")
>
> Then we're GError compatible.  If we throw away our existing error
> infrastructure and incrementally adopt GError, then that excites me :-)
>
>> If error_setf() ends result is similar to what this series does with
>> error_set(), then that might be acceptable, although I fear we keep
>> adding new ways to report errors.
>
> I think having an end goal of using GError is a good way to avoid the
> never ending cycle of inventing a better mouse trap.

I don't see what domain buys us.  Please explain.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
                   ` (14 preceding siblings ...)
  2012-07-26  2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
@ 2012-07-26 15:54 ` Markus Armbruster
  2012-07-26 16:03   ` Paolo Bonzini
  15 siblings, 1 reply; 37+ messages in thread
From: Markus Armbruster @ 2012-07-26 15:54 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: peter.maydell, pbonzini, aliguori, qemu-devel, afaerber

Unlike Anthony, I think this is a move in the right direction.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 15:54 ` Markus Armbruster
@ 2012-07-26 16:03   ` Paolo Bonzini
  2012-07-26 16:37     ` Luiz Capitulino
  0 siblings, 1 reply; 37+ messages in thread
From: Paolo Bonzini @ 2012-07-26 16:03 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: peter.maydell, aliguori, qemu-devel, afaerber, Luiz Capitulino

Il 26/07/2012 17:54, Markus Armbruster ha scritto:
> Unlike Anthony, I think this is a move in the right direction.

Me too, but I would like to understand how it fits with the
qapi-schema-errors.json.  Do we actually need a schema if the messages
are flat?

Paolo

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26  2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
  2012-07-26  9:45   ` Kevin Wolf
@ 2012-07-26 16:12   ` Daniel P. Berrange
  2012-07-26 16:38     ` Markus Armbruster
  1 sibling, 1 reply; 37+ messages in thread
From: Daniel P. Berrange @ 2012-07-26 16:12 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: peter.maydell, qemu-devel, armbru, pbonzini, Luiz Capitulino, afaerber

On Wed, Jul 25, 2012 at 09:43:55PM -0500, Anthony Liguori wrote:
> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > Basically, this series changes a call like:
> >
> >  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> >
> > to:
> >
> >  error_set(errp, QERR_DEVICE_NOT_FOUND,
> >            "Device 'device=%s' not found", device);
> >
> > In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
> >
> >     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
> 
> This is the wrong direction.  Looking through the patch, this makes the
> code much more redundant overall.  You have dozens of calls that are
> duplicating the same error message.  This is not progress.

What we do in libvirt, is to define helper functions for
reporting the specific error codes. So, as well as having
the generic

  error_set(errp, QERR_CODE, "format string", args)

you would have

  error_set_device_not_found(errp, args)

which is just a #define

  #define error_set_device_not_found(errp, args) \
     error_set(errp, QERR_DEVICE_NOT_FOUND, "Device %s not found", args)

for the most part this should avoid the duplication you're concerned
about, while still letting use provided more detailed messsages.


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 16:03   ` Paolo Bonzini
@ 2012-07-26 16:37     ` Luiz Capitulino
  2012-07-27 13:17       ` Andreas Färber
  0 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-26 16:37 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: peter.maydell, aliguori, Markus Armbruster, afaerber, qemu-devel

On Thu, 26 Jul 2012 18:03:20 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Il 26/07/2012 17:54, Markus Armbruster ha scritto:
> > Unlike Anthony, I think this is a move in the right direction.
> 
> Me too, but I would like to understand how it fits with the
> qapi-schema-errors.json.  Do we actually need a schema if the messages
> are flat?

Yes, we need it because we still an error object to obey (ie. the data member).

But we're talking about dropping that, so it might be possible to kill
the schema.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 16:12   ` Daniel P. Berrange
@ 2012-07-26 16:38     ` Markus Armbruster
  0 siblings, 0 replies; 37+ messages in thread
From: Markus Armbruster @ 2012-07-26 16:38 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: peter.maydell, Anthony Liguori, qemu-devel, Luiz Capitulino,
	pbonzini, afaerber

"Daniel P. Berrange" <berrange@redhat.com> writes:

> On Wed, Jul 25, 2012 at 09:43:55PM -0500, Anthony Liguori wrote:
>> Luiz Capitulino <lcapitulino@redhat.com> writes:
>> 
>> > Basically, this series changes a call like:
>> >
>> >  error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>> >
>> > to:
>> >
>> >  error_set(errp, QERR_DEVICE_NOT_FOUND,
>> >            "Device 'device=%s' not found", device);
>> >
>> > In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:
>> >
>> >     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
>> 
>> This is the wrong direction.  Looking through the patch, this makes the
>> code much more redundant overall.  You have dozens of calls that are
>> duplicating the same error message.  This is not progress.
>
> What we do in libvirt, is to define helper functions for
> reporting the specific error codes. So, as well as having
> the generic
>
>   error_set(errp, QERR_CODE, "format string", args)
>
> you would have
>
>   error_set_device_not_found(errp, args)
>
> which is just a #define
>
>   #define error_set_device_not_found(errp, args) \
>      error_set(errp, QERR_DEVICE_NOT_FOUND, "Device %s not found", args)
>
> for the most part this should avoid the duplication you're concerned
> about, while still letting use provided more detailed messsages.

Yup.  I suggested the same on IRC, modulo macro vs. function.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-26 16:37     ` Luiz Capitulino
@ 2012-07-27 13:17       ` Andreas Färber
  2012-07-27 13:45         ` Anthony Liguori
  2012-07-27 14:27         ` Luiz Capitulino
  0 siblings, 2 replies; 37+ messages in thread
From: Andreas Färber @ 2012-07-27 13:17 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: peter.maydell, Paolo Bonzini, aliguori, Markus Armbruster, qemu-devel

Am 26.07.2012 18:37, schrieb Luiz Capitulino:
> On Thu, 26 Jul 2012 18:03:20 +0200
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> Il 26/07/2012 17:54, Markus Armbruster ha scritto:
>>> Unlike Anthony, I think this is a move in the right direction.
>>
>> Me too, but I would like to understand how it fits with the
>> qapi-schema-errors.json.  Do we actually need a schema if the messages
>> are flat?
> 
> Yes, we need it because we still an error object to obey (ie. the data member).
> 
> But we're talking about dropping that, so it might be possible to kill
> the schema.

I'm not so familiar with how all this error infrastructure is plugged
together...

In a different thread that I mentioned recently (and still haven't found
in my inbox), we were talking about changing the JSON encoding of errors
where unused by libvirt. Specifically we were talking about having a
field for the canonical QOM path of the affected object in place of the
often-empty device ID.

Are you now discussing to drop any such elaborated QMP schemes in place
of just one non-parsable human error message string?

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-27 13:17       ` Andreas Färber
@ 2012-07-27 13:45         ` Anthony Liguori
  2012-07-27 14:27         ` Luiz Capitulino
  1 sibling, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2012-07-27 13:45 UTC (permalink / raw)
  To: Andreas Färber, Luiz Capitulino
  Cc: peter.maydell, Paolo Bonzini, Markus Armbruster, qemu-devel

Andreas Färber <afaerber@suse.de> writes:

> Am 26.07.2012 18:37, schrieb Luiz Capitulino:
>> On Thu, 26 Jul 2012 18:03:20 +0200
>> Paolo Bonzini <pbonzini@redhat.com> wrote:
>> 
>>> Il 26/07/2012 17:54, Markus Armbruster ha scritto:
>>>> Unlike Anthony, I think this is a move in the right direction.
>>>
>>> Me too, but I would like to understand how it fits with the
>>> qapi-schema-errors.json.  Do we actually need a schema if the messages
>>> are flat?
>> 
>> Yes, we need it because we still an error object to obey (ie. the data member).
>> 
>> But we're talking about dropping that, so it might be possible to kill
>> the schema.
>
> I'm not so familiar with how all this error infrastructure is plugged
> together...
>
> In a different thread that I mentioned recently (and still haven't found
> in my inbox), we were talking about changing the JSON encoding of errors
> where unused by libvirt. Specifically we were talking about having a
> field for the canonical QOM path of the affected object in place of the
> often-empty device ID.
>
> Are you now discussing to drop any such elaborated QMP schemes in place
> of just one non-parsable human error message string?

See the other note I sent out for a description of the plan.  It's
english string + error code.

Regards,

Anthony Liguori

>
> Andreas
>
> -- 
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()
  2012-07-27 13:17       ` Andreas Färber
  2012-07-27 13:45         ` Anthony Liguori
@ 2012-07-27 14:27         ` Luiz Capitulino
  1 sibling, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2012-07-27 14:27 UTC (permalink / raw)
  To: Andreas Färber
  Cc: peter.maydell, Paolo Bonzini, aliguori, Markus Armbruster, qemu-devel

On Fri, 27 Jul 2012 15:17:15 +0200
Andreas Färber <afaerber@suse.de> wrote:

> Am 26.07.2012 18:37, schrieb Luiz Capitulino:
> > On Thu, 26 Jul 2012 18:03:20 +0200
> > Paolo Bonzini <pbonzini@redhat.com> wrote:
> > 
> >> Il 26/07/2012 17:54, Markus Armbruster ha scritto:
> >>> Unlike Anthony, I think this is a move in the right direction.
> >>
> >> Me too, but I would like to understand how it fits with the
> >> qapi-schema-errors.json.  Do we actually need a schema if the messages
> >> are flat?
> > 
> > Yes, we need it because we still an error object to obey (ie. the data member).
> > 
> > But we're talking about dropping that, so it might be possible to kill
> > the schema.
> 
> I'm not so familiar with how all this error infrastructure is plugged
> together...
> 
> In a different thread that I mentioned recently (and still haven't found
> in my inbox), we were talking about changing the JSON encoding of errors
> where unused by libvirt. Specifically we were talking about having a
> field for the canonical QOM path of the affected object in place of the
> often-empty device ID.

We don't send empty device IDs afaik, but that problem will have to be
discussed again... Why does libvirt need the QOM path from the error
message? Can't it be queried some other way?

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2012-07-27 14:27 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Luiz Capitulino
2012-07-26 12:33   ` Markus Armbruster
2012-07-26 15:02     ` Luiz Capitulino
2012-07-26 12:59   ` Eric Blake
2012-07-25 20:50 ` [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal() Luiz Capitulino
2012-07-26 12:35   ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 07/14] error: " Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[] Luiz Capitulino
2012-07-26 12:52   ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 10/14] error: error_set(): " Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good Luiz Capitulino
2012-07-26 12:54   ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 14/14] error: change all error_set() " Luiz Capitulino
2012-07-26  2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
2012-07-26  9:45   ` Kevin Wolf
2012-07-26 12:41     ` Anthony Liguori
2012-07-26 14:12       ` Luiz Capitulino
2012-07-26 15:05         ` Anthony Liguori
2012-07-26 15:52           ` Markus Armbruster
2012-07-26 14:40       ` Kevin Wolf
2012-07-26 15:20         ` Anthony Liguori
2012-07-26 16:12   ` Daniel P. Berrange
2012-07-26 16:38     ` Markus Armbruster
2012-07-26 15:54 ` Markus Armbruster
2012-07-26 16:03   ` Paolo Bonzini
2012-07-26 16:37     ` Luiz Capitulino
2012-07-27 13:17       ` Andreas Färber
2012-07-27 13:45         ` Anthony Liguori
2012-07-27 14:27         ` Luiz Capitulino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.