diff options
author | Markus Armbruster <armbru@redhat.com> | 2018-10-17 10:26:25 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-10-19 14:51:34 +0200 |
commit | 4b5766488fd3549dc47a75331cf4db62f477536c (patch) | |
tree | ded71544d77610628957f5be840439cbf0b26455 /include/qapi | |
parent | d7ecf712382486ef0d79fe335f5abb333b44d279 (diff) | |
download | qemu-4b5766488fd3549dc47a75331cf4db62f477536c.zip qemu-4b5766488fd3549dc47a75331cf4db62f477536c.tar.gz qemu-4b5766488fd3549dc47a75331cf4db62f477536c.tar.bz2 |
error: Fix use of error_prepend() with &error_fatal, &error_abort
From include/qapi/error.h:
* Pass an existing error to the caller with the message modified:
* error_propagate(errp, err);
* error_prepend(errp, "Could not frobnicate '%s': ", name);
Fei Li pointed out that doing error_propagate() first doesn't work
well when @errp is &error_fatal or &error_abort: the error_prepend()
is never reached.
Since I doubt fixing the documentation will stop people from getting
it wrong, introduce error_propagate_prepend(), in the hope that it
lures people away from using its constituents in the wrong order.
Update the instructions in error.h accordingly.
Convert existing error_prepend() next to error_propagate to
error_propagate_prepend(). If any of these get reached with
&error_fatal or &error_abort, the error messages improve. I didn't
check whether that's the case anywhere.
Cc: Fei Li <fli@suse.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20181017082702.5581-2-armbru@redhat.com>
Diffstat (limited to 'include/qapi')
-rw-r--r-- | include/qapi/error.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/qapi/error.h b/include/qapi/error.h index bcb86a7..51b63dd 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -52,8 +52,12 @@ * where Error **errp is a parameter, by convention the last one. * * Pass an existing error to the caller with the message modified: + * error_propagate_prepend(errp, err); + * + * Avoid * error_propagate(errp, err); * error_prepend(errp, "Could not frobnicate '%s': ", name); + * because this fails to prepend when @errp is &error_fatal. * * Create a new error and pass it to the caller: * error_setg(errp, "situation normal, all fouled up"); @@ -215,6 +219,16 @@ void error_setg_win32_internal(Error **errp, */ void error_propagate(Error **dst_errp, Error *local_err); + +/* + * Propagate error object (if any) with some text prepended. + * Behaves like + * error_prepend(&local_err, fmt, ...); + * error_propagate(dst_errp, local_err); + */ +void error_propagate_prepend(Error **dst_errp, Error *local_err, + const char *fmt, ...); + /* * Prepend some text to @errp's human-readable error message. * The text is made by formatting @fmt, @ap like vprintf(). |