c687bc
From fe7dd779a9674dc54ffe296247ae6559f2b55b22 Mon Sep 17 00:00:00 2001
c687bc
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
c687bc
Date: Wed, 16 Dec 2020 16:06:07 -0500
c687bc
Subject: [PATCH 06/14] error: Fix examples in error.h's big comment
c687bc
MIME-Version: 1.0
c687bc
Content-Type: text/plain; charset=UTF-8
c687bc
Content-Transfer-Encoding: 8bit
c687bc
c687bc
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
c687bc
Message-id: <20201216160615.324213-3-marcandre.lureau@redhat.com>
c687bc
Patchwork-id: 100473
c687bc
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 02/10] error: Fix examples in error.h's big comment
c687bc
Bugzilla: 1859494
c687bc
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
c687bc
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
c687bc
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
c687bc
c687bc
From: Markus Armbruster <armbru@redhat.com>
c687bc
c687bc
Mark a bad example more clearly.  Fix the error_propagate_prepend()
c687bc
example.  Add a missing declaration and a second error pileup example.
c687bc
c687bc
Signed-off-by: Markus Armbruster <armbru@redhat.com>
c687bc
Reviewed-by: Eric Blake <eblake@redhat.com>
c687bc
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
c687bc
Reviewed-by: Greg Kurz <groug@kaod.org>
c687bc
Message-Id: <20200707160613.848843-2-armbru@redhat.com>
c687bc
c687bc
(cherry picked from commit 47ff5ac81e8bb3096500de7b132051691d533d36)
c687bc
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
c687bc
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
c687bc
---
c687bc
 include/qapi/error.h | 16 ++++++++++++++--
c687bc
 1 file changed, 14 insertions(+), 2 deletions(-)
c687bc
c687bc
diff --git a/include/qapi/error.h b/include/qapi/error.h
c687bc
index 3f95141a01a..83c38f9a188 100644
c687bc
--- a/include/qapi/error.h
c687bc
+++ b/include/qapi/error.h
c687bc
@@ -24,7 +24,7 @@
c687bc
  *                       "charm, top, bottom.\n");
c687bc
  *
c687bc
  * Do *not* contract this to
c687bc
- *     error_setg(&err, "invalid quark\n"
c687bc
+ *     error_setg(&err, "invalid quark\n" // WRONG!
c687bc
  *                "Valid quarks are up, down, strange, charm, top, bottom.");
c687bc
  *
c687bc
  * Report an error to the current monitor if we have one, else stderr:
c687bc
@@ -52,7 +52,8 @@
c687bc
  * where Error **errp is a parameter, by convention the last one.
c687bc
  *
c687bc
  * Pass an existing error to the caller with the message modified:
c687bc
- *     error_propagate_prepend(errp, err);
c687bc
+ *     error_propagate_prepend(errp, err,
c687bc
+ *                             "Could not frobnicate '%s': ", name);
c687bc
  *
c687bc
  * Avoid
c687bc
  *     error_propagate(errp, err);
c687bc
@@ -108,12 +109,23 @@
c687bc
  *     }
c687bc
  *
c687bc
  * Do *not* "optimize" this to
c687bc
+ *     Error *err = NULL;
c687bc
  *     foo(arg, &err;;
c687bc
  *     bar(arg, &err;; // WRONG!
c687bc
  *     if (err) {
c687bc
  *         handle the error...
c687bc
  *     }
c687bc
  * because this may pass a non-null err to bar().
c687bc
+ *
c687bc
+ * Likewise, do *not*
c687bc
+ *     Error *err = NULL;
c687bc
+ *     if (cond1) {
c687bc
+ *         error_setg(&err, ...);
c687bc
+ *     }
c687bc
+ *     if (cond2) {
c687bc
+ *         error_setg(&err, ...); // WRONG!
c687bc
+ *     }
c687bc
+ * because this may pass a non-null err to error_setg().
c687bc
  */
c687bc
 
c687bc
 #ifndef ERROR_H
c687bc
-- 
c687bc
2.27.0
c687bc