Message ID | 20201030202131.796967-2-ehabkost@redhat.com |
---|---|
State | New |
Headers | show |
Series | qdev/qom: Remove explicit type names from error_setg() calls | expand |
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 --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; }
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(+)