diff mbox series

[01/20] qom: Add prefix to error message inside object_property_parse()

Message ID 20201030202131.796967-2-ehabkost@redhat.com
State New
Headers show
Series qdev/qom: Remove explicit type names from error_setg() calls | expand

Commit Message

Eduardo Habkost Oct. 30, 2020, 8:21 p.m. UTC
Make object_property_parse() automatically add a error message
prefix mentioning the QOM type and property name when
encountering errors.

As we have a large number of functions that add their own
"Property '...'" to the error messages, add a temporary check for
existing prefixes before prepending our own.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 qom/object.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Igor Mammedov Nov. 3, 2020, 12:33 p.m. UTC | #1
On Fri, 30 Oct 2020 16:21:12 -0400
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Make object_property_parse() automatically add a error message
> prefix mentioning the QOM type and property name when
> encountering errors.
> 
> As we have a large number of functions that add their own
> "Property '...'" to the error messages, add a temporary check for
> existing prefixes before prepending our own.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: "Daniel P. Berrangé" <berrange@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  qom/object.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 20726e4584..6fb1657724 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1635,9 +1635,20 @@ int object_property_get_enum(Object *obj, const char *name,
>  bool object_property_parse(Object *obj, const char *name,
>                             const char *string, Error **errp)
>  {
> +    ERRP_GUARD();
>      Visitor *v = string_input_visitor_new(string);
>      bool ok = object_property_set(obj, name, v, errp);
>  
> +    if (!ok) {
> +        /*
> +         * Temporary check for existing prefix, until all error reporting
> +         * functions remove their own prefix.
> +         */
> +        if (!g_str_has_prefix(error_get_pretty(*errp), "Property '")) {
> +            error_prepend(errp, "Property '%s.%s' can't take value '%s': ",
> +                        object_get_typename(obj), name, string);
> +        }
> +    }
>      visit_free(v);
>      return ok;
>  }
diff mbox series

Patch

diff --git a/qom/object.c b/qom/object.c
index 20726e4584..6fb1657724 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1635,9 +1635,20 @@  int object_property_get_enum(Object *obj, const char *name,
 bool object_property_parse(Object *obj, const char *name,
                            const char *string, Error **errp)
 {
+    ERRP_GUARD();
     Visitor *v = string_input_visitor_new(string);
     bool ok = object_property_set(obj, name, v, errp);
 
+    if (!ok) {
+        /*
+         * Temporary check for existing prefix, until all error reporting
+         * functions remove their own prefix.
+         */
+        if (!g_str_has_prefix(error_get_pretty(*errp), "Property '")) {
+            error_prepend(errp, "Property '%s.%s' can't take value '%s': ",
+                        object_get_typename(obj), name, string);
+        }
+    }
     visit_free(v);
     return ok;
 }