error: Document how to accumulate multiple errors
authorMarkus Armbruster <armbru@redhat.com>
Tue, 17 Nov 2015 16:05:49 +0000 (17:05 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Wed, 13 Jan 2016 10:58:57 +0000 (11:58 +0100)
Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447776349-2344-1-git-send-email-armbru@redhat.com>

include/qapi/error.h

index 6285cf50d1f6ee66c2658817464f4f23bfc3d934..1480f59ec57f36c4ac272eff1eed9cf60df4c945 100644 (file)
  * But when all you do with the error is pass it on, please use
  *     foo(arg, errp);
  * for readability.
+ *
+ * Receive and accumulate multiple errors (first one wins):
+ *     Error *err = NULL, *local_err = NULL;
+ *     foo(arg, &err);
+ *     bar(arg, &local_err);
+ *     error_propagate(&err, local_err);
+ *     if (err) {
+ *         handle the error...
+ *     }
+ *
+ * Do *not* "optimize" this to
+ *     foo(arg, &err);
+ *     bar(arg, &err); // WRONG!
+ *     if (err) {
+ *         handle the error...
+ *     }
+ * because this may pass a non-null err to bar().
  */
 
 #ifndef ERROR_H