Re: [PATCH v3 00/44] Less clumsy error checking
On 7/6/20 3:12 AM, Markus Armbruster wrote: diff between v2 rebased and v3, with hunks that change only whitespace dropped: Thanks, that's useful. Overall, the series looks ready to go from my perspective. It looks like the changes from v2 were minimal enough that I don't have any R-b to add. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 00/44] Less clumsy error checking
diff between v2 rebased and v3, with hunks that change only whitespace dropped: diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 6d8f4b6928..7781c23a42 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -235,12 +235,12 @@ opts_start_list(Visitor *v, const char *name, GenericList **list, size_t size, /* we don't support visits without a list */ assert(list); ov->repeated_opts = lookup_distinct(ov, name, errp); -if (ov->repeated_opts) { -ov->list_mode = LM_IN_PROGRESS; -*list = g_malloc0(size); -} else { +if (!ov->repeated_opts) { *list = NULL; +return false; } +ov->list_mode = LM_IN_PROGRESS; +*list = g_malloc0(size); return true; } diff --git a/qapi/qapi-clone-visitor.c b/qapi/qapi-clone-visitor.c index 5a54bd593f..c45c5caa3b 100644 --- a/qapi/qapi-clone-visitor.c +++ b/qapi/qapi-clone-visitor.c @@ -56,8 +56,7 @@ static bool qapi_clone_start_list(Visitor *v, const char *name, GenericList **listp, size_t size, Error **errp) { -qapi_clone_start_struct(v, name, (void **)listp, size, errp); -return true; +return qapi_clone_start_struct(v, name, (void **)listp, size, errp); } static GenericList *qapi_clone_next_list(Visitor *v, GenericList *tail, @@ -75,8 +74,7 @@ static bool qapi_clone_start_alternate(Visitor *v, const char *name, GenericAlternate **obj, size_t size, Error **errp) { -qapi_clone_start_struct(v, name, (void **)obj, size, errp); -return true; +return qapi_clone_start_struct(v, name, (void **)obj, size, errp); } static bool qapi_clone_type_int64(Visitor *v, const char *name, int64_t *obj, diff --git a/qdev-monitor.c b/qdev-monitor.c index 7ebb97cf0d..31cc1f6564 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -652,7 +652,6 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) /* Check whether the hotplug is allowed by the machine */ if (qdev_hotplug && !qdev_hotplug_allowed(dev, errp)) { -/* Error must be set in the machine hook */ goto err_del_dev; } diff --git a/qom/object.c b/qom/object.c index 8d698abf4d..d6bba48e41 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1773,21 +1773,24 @@ static void object_set_link_property(Object *obj, Visitor *v, LinkProperty *prop = opaque; Object **targetp = object_link_get_targetp(obj, prop); Object *old_target = *targetp; -Object *new_target = NULL; +Object *new_target; char *path = NULL; if (!visit_type_str(v, name, , errp)) { return; } -if (strcmp(path, "") != 0) { +if (*path) { new_target = object_resolve_link(obj, name, path, errp); +if (!new_target) { +g_free(path); +return; +} +} else { +new_target = NULL; } g_free(path); -if (!new_target) { -return; -} prop->check(obj, name, new_target, _err); if (local_err) {
[PATCH v3 00/44] Less clumsy error checking
When the Error API was created, we adopted the (unwritten) rule to return void when the function returns no useful value on success, unlike GError, which recommends to return true on success and false on error then. When a function returns a distinct error value, say false, a checked call that passes the error up looks like if (!frobnicate(..., errp)) { handle the error... } When it returns void, we need Error *err = NULL; frobnicate(..., ); if (err) { handle the error... error_propagate(errp, err); } Not only is this more verbose, it also creates an Error object even when @errp is null, _abort or _fatal. People got tired of the additional boilerplate, and started to ignore the unwritten rule. The result is confusion among developers about the preferred usage. This series adopts the GError rule (in writing), and updates a substantial amount of code to honor the rule. Cuts the number of error_propagate() calls nearly by half. The diffstat speaks for itself. Also available from my public repository https://repo.or.cz/qemu/armbru.git on branch error-smooth. v3: * Rebased * Fix patch ordering: old PATCH 19 becomes PATCH 37 * PATCH 03+13+25+27: Avoid long lines in Coccinelle script [Eric] * PATCH 14: Fix commit message typo [Eric] * PATCH 16: Unbreak opts_start_list(), qapi_clone_start_list(), qapi_clone_start_alternate() [Vladimir] * PATCH 24: Unbreak object_set_link_property() [Vladimir] * PATCH 25+33+35: Move unrelated hunks from 25 to 33 and 35 [Vladimir], tweak line breaks * PATCH 32: Have commit message point out the unnecessary error_propagate() will be eliminated shortly [Eric] * PATCH 33: Fix commit message typo [Eric] * PATCH 35: Delete comment along with the assertion [Eric] * Left for later: followup to fix nearby typos and such [Eric] v2: * Rebased * Coccinelle scripts reworked, patches sliced and diced for reviewability: Old PATCH 03+17+23-24+35+38-39+42 split into "Use returned bool to check for failure" parts [PATCH 03+13+17-18+25+28-29+42], and "Eliminate error_propagate()" parts. The latter combined with old PATCH 06-07+18-19+29+43 are now [PATCH 33-37]. The end result is almost identical. Some R-bys dropped; sorry! * Drop variables as they become unused [Vladimir] * PATCH 01: Comment typos fixed [Greg] * PATCH 09: Simplify further by cutting out variables [Eric] * PATCH 11: opt_set() renamed to opt_validate(), redundant parameter dropped [Vladimir], R-by kept * PATCH 16: Comment typos fixed, indentation tidied up [Eric] * PATCH 23: Assertion dropped [Eric], incorrect hunk backed out * PATCH 26: Regenerated after rebase; note additional Coccinelle hiccup in the commit message * PATCH 27: Indentation tiedied up [Eric] * Left for later: followup to fix nearby typos and such [Eric] Markus Armbruster (44): error: Improve examples in error.h's big comment error: Document Error API usage rules qdev: Use returned bool to check for qdev_realize() etc. failure macio: Tidy up error handling in macio_newworld_realize() virtio-crypto-pci: Tidy up virtio_crypto_pci_realize() qemu-option: Check return value instead of @err where convenient qemu-option: Make uses of find_desc_by_name() more similar qemu-option: Factor out helper find_default_by_name() qemu-option: Simplify around find_default_by_name() qemu-option: Factor out helper opt_create() qemu-option: Replace opt_set() by cleaner opt_validate() qemu-option: Make functions taking Error ** return bool, not void qemu-option: Use returned bool to check for failure block: Avoid error accumulation in bdrv_img_create() hmp: Eliminate a variable in hmp_migrate_set_parameter() qapi: Make visitor functions taking Error ** return bool, not void qapi: Use returned bool to check for failure, Coccinelle part qapi: Use returned bool to check for failure, manual part s390x/pci: Fix harmless mistake in zpci's property fid's setter qom: Use error_reportf_err() instead of g_printerr() in examples qom: Rename qdev_get_type() to object_get_type() qom: Crash more nicely on object_property_get_link() failure qom: Don't handle impossible object_property_get_link() failure qom: Use return values to check for error where that's simpler qom: Put name parameter before value / visitor parameter qom: Make functions taking Error ** return bool, not void qom: Use returned bool to check for failure, Coccinelle part qom: Use returned bool to check for failure, manual part qom: Make functions taking Error ** return bool, not 0/-1 qdev: Make functions taking Error ** return bool, not void qdev: Use returned bool to check for failure, Coccinelle part error: Avoid unnecessary error_propagate() after error_setg() error: Eliminate error_propagate() with Coccinelle, part 1 error: Eliminate error_propagate() with Coccinelle, part 2 error: Eliminate error_propagate() manually error: Reduce unnecessary error propagation