From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH for-2.5] error: Document chained error handling
Date: Thu, 12 Nov 2015 11:20:54 -0700 [thread overview]
Message-ID: <1447352454-29349-1-git-send-email-eblake@redhat.com> (raw)
The current output of the qapi code generator includes some chained
error handling, which looks like:
| visit_start_struct(v, (void **)obj, "foo", name, sizeof(FOO), &err);
| if (!err) {
| if (*obj) {
| visit_type_FOO_fields(v, obj, errp);
| }
| visit_end_struct(v, &err);
| }
| error_propagate(errp, err);
Although there are plans to revisit that code for qemu 2.6, it is
still a useful idiom to mention. It is safe because error_propagate()
is different than most functions in that you can pass in an
already-set errp, and it still does the right thing.
Also, describe an alternative form of chained error handling that was
proposed during the qapi work, and which may be a bit more obvious
to a reader what is happening:
| visit_start_implicit_struct(v, (void **)obj, sizeof(FOO), &err);
| if (!err) {
| visit_type_FOO_fields(v, obj, &err);
| visit_end_implicit_struct(v, err ? NULL : &err);
| }
| error_propagate(errp, err);
Signed-off-by: Eric Blake <eblake@redhat.com>
---
based on feedback of my qapi series v5 7/46; doc only, so might
be worth having in 2.5
---
include/qapi/error.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/qapi/error.h b/include/qapi/error.h
index 4d42cdc..4310195 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -76,6 +76,21 @@
* But when all you do with the error is pass it on, please use
* foo(arg, errp);
* for readability.
+ *
+ * In a situation where cleanup must happen even if a first step fails,
+ * but the cleanup may also set an error, the first error to occur will
+ * take priority when combined by:
+ * Error *err = NULL;
+ * action1(arg, errp);
+ * action2(arg, &err);
+ * error_propagate(errp, err);
+ * or by:
+ * Error *err = NULL;
+ * action1(arg, &err);
+ * action2(arg, err ? NULL : &err);
+ * error_propagate(errp, err);
+ * although the second form is required if any further error handling
+ * will inspect err to see if all earlier locations succeeded.
*/
#ifndef ERROR_H
--
2.4.3
next reply other threads:[~2015-11-12 18:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-12 18:20 Eric Blake [this message]
2015-11-17 13:48 ` [Qemu-devel] [PATCH for-2.5] error: Document chained error handling Markus Armbruster
2015-11-17 15:11 ` Eric Blake
2015-11-17 15:36 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447352454-29349-1-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).