diff mbox series

keyval: Print types on merge inconsistency

Message ID 20220913100811.99746-1-dgilbert@redhat.com (mailing list archive)
State New, archived
Headers show
Series keyval: Print types on merge inconsistency | expand

Commit Message

Dr. David Alan Gilbert Sept. 13, 2022, 10:08 a.m. UTC
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

When 'keyval_do_merge' checks consistency of types, if they mismatch
print the types so we get a hint of what's going on.

e.g.
qemu-system-x86_64: Parameter 'memory' used inconsistently (qstring/qdict)

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 util/keyval.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Markus Armbruster Sept. 16, 2022, 5:47 a.m. UTC | #1
"Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> writes:

> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> When 'keyval_do_merge' checks consistency of types, if they mismatch
> print the types so we get a hint of what's going on.
>
> e.g.
> qemu-system-x86_64: Parameter 'memory' used inconsistently (qstring/qdict)
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  util/keyval.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/util/keyval.c b/util/keyval.c
> index 66a5b4740f..9757adf31f 100644
> --- a/util/keyval.c
> +++ b/util/keyval.c
> @@ -329,8 +329,10 @@ static void keyval_do_merge(QDict *dest, const QDict *merged, GString *str, Erro
>          old_value = qdict_get(dest, ent->key);
>          if (old_value) {
>              if (qobject_type(old_value) != qobject_type(ent->value)) {
> -                error_setg(errp, "Parameter '%s%s' used inconsistently",
> -                           str->str, ent->key);
> +                error_setg(errp, "Parameter '%s%s' used inconsistently (%s/%s)",
> +                           str->str, ent->key,
> +                           QType_str(qobject_type(old_value)),
> +                           QType_str(qobject_type(ent->value)));

Two more, one in keyval_parse_put(), and one in keyval_listify().

The error message talks in developer terms.  Can we talk in user terms
instead?  Could showing the conflicting key suffice?

>                  return;
>              } else if (qobject_type(ent->value) == QTYPE_QDICT) {
>                  /* Merge sub-dictionaries.  */
diff mbox series

Patch

diff --git a/util/keyval.c b/util/keyval.c
index 66a5b4740f..9757adf31f 100644
--- a/util/keyval.c
+++ b/util/keyval.c
@@ -329,8 +329,10 @@  static void keyval_do_merge(QDict *dest, const QDict *merged, GString *str, Erro
         old_value = qdict_get(dest, ent->key);
         if (old_value) {
             if (qobject_type(old_value) != qobject_type(ent->value)) {
-                error_setg(errp, "Parameter '%s%s' used inconsistently",
-                           str->str, ent->key);
+                error_setg(errp, "Parameter '%s%s' used inconsistently (%s/%s)",
+                           str->str, ent->key,
+                           QType_str(qobject_type(old_value)),
+                           QType_str(qobject_type(ent->value)));
                 return;
             } else if (qobject_type(ent->value) == QTYPE_QDICT) {
                 /* Merge sub-dictionaries.  */