thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
c687bc
From 439c11850165fd838e367aa6d4fff4af951a5bd9 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:08 -0500
c687bc
Subject: [PATCH 07/14] error: Improve 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-4-marcandre.lureau@redhat.com>
c687bc
Patchwork-id: 100474
c687bc
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 03/10] error: Improve 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
Add headlines to the big comment.
c687bc
c687bc
Explain examples for NULL, &error_abort and &error_fatal argument
c687bc
better.
c687bc
c687bc
Tweak rationale for error_propagate_prepend().
c687bc
c687bc
Signed-off-by: Markus Armbruster <armbru@redhat.com>
c687bc
Message-Id: <20200707160613.848843-3-armbru@redhat.com>
c687bc
Reviewed-by: Eric Blake <eblake@redhat.com>
c687bc
Reviewed-by: Greg Kurz <groug@kaod.org>
c687bc
c687bc
(cherry picked from commit 9aac7d486cc792191c25c30851f501624b0c2751)
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 | 51 +++++++++++++++++++++++++++++++-------------
c687bc
 1 file changed, 36 insertions(+), 15 deletions(-)
c687bc
c687bc
diff --git a/include/qapi/error.h b/include/qapi/error.h
c687bc
index 83c38f9a188..3351fe76368 100644
c687bc
--- a/include/qapi/error.h
c687bc
+++ b/include/qapi/error.h
c687bc
@@ -15,6 +15,8 @@
c687bc
 /*
c687bc
  * Error reporting system loosely patterned after Glib's GError.
c687bc
  *
c687bc
+ * = Creating errors =
c687bc
+ *
c687bc
  * Create an error:
c687bc
  *     error_setg(&err, "situation normal, all fouled up");
c687bc
  *
c687bc
@@ -27,6 +29,8 @@
c687bc
  *     error_setg(&err, "invalid quark\n" // WRONG!
c687bc
  *                "Valid quarks are up, down, strange, charm, top, bottom.");
c687bc
  *
c687bc
+ * = Reporting and destroying errors =
c687bc
+ *
c687bc
  * Report an error to the current monitor if we have one, else stderr:
c687bc
  *     error_report_err(err);
c687bc
  * This frees the error object.
c687bc
@@ -40,6 +44,30 @@
c687bc
  *     error_free(err);
c687bc
  * Note that this loses hints added with error_append_hint().
c687bc
  *
c687bc
+ * Call a function ignoring errors:
c687bc
+ *     foo(arg, NULL);
c687bc
+ * This is more concise than
c687bc
+ *     Error *err = NULL;
c687bc
+ *     foo(arg, &err;;
c687bc
+ *     error_free(err); // don't do this
c687bc
+ *
c687bc
+ * Call a function aborting on errors:
c687bc
+ *     foo(arg, &error_abort);
c687bc
+ * This is more concise and fails more nicely than
c687bc
+ *     Error *err = NULL;
c687bc
+ *     foo(arg, &err;;
c687bc
+ *     assert(!err); // don't do this
c687bc
+ *
c687bc
+ * Call a function treating errors as fatal:
c687bc
+ *     foo(arg, &error_fatal);
c687bc
+ * This is more concise than
c687bc
+ *     Error *err = NULL;
c687bc
+ *     foo(arg, &err;;
c687bc
+ *     if (err) { // don't do this
c687bc
+ *         error_report_err(err);
c687bc
+ *         exit(1);
c687bc
+ *     }
c687bc
+ *
c687bc
  * Handle an error without reporting it (just for completeness):
c687bc
  *     error_free(err);
c687bc
  *
c687bc
@@ -47,6 +75,11 @@
c687bc
  * reporting it (primarily useful in testsuites):
c687bc
  *     error_free_or_abort(&err;;
c687bc
  *
c687bc
+ * = Passing errors around =
c687bc
+ *
c687bc
+ * Errors get passed to the caller through the conventional @errp
c687bc
+ * parameter.
c687bc
+ *
c687bc
  * Pass an existing error to the caller:
c687bc
  *     error_propagate(errp, err);
c687bc
  * where Error **errp is a parameter, by convention the last one.
c687bc
@@ -54,11 +87,10 @@
c687bc
  * Pass an existing error to the caller with the message modified:
c687bc
  *     error_propagate_prepend(errp, err,
c687bc
  *                             "Could not frobnicate '%s': ", name);
c687bc
- *
c687bc
- * Avoid
c687bc
- *     error_propagate(errp, err);
c687bc
+ * This is more concise than
c687bc
+ *     error_propagate(errp, err); // don't do this
c687bc
  *     error_prepend(errp, "Could not frobnicate '%s': ", name);
c687bc
- * because this fails to prepend when @errp is &error_fatal.
c687bc
+ * and works even when @errp is &error_fatal.
c687bc
  *
c687bc
  * Create a new error and pass it to the caller:
c687bc
  *     error_setg(errp, "situation normal, all fouled up");
c687bc
@@ -70,15 +102,6 @@
c687bc
  *         handle the error...
c687bc
  *     }
c687bc
  *
c687bc
- * Call a function ignoring errors:
c687bc
- *     foo(arg, NULL);
c687bc
- *
c687bc
- * Call a function aborting on errors:
c687bc
- *     foo(arg, &error_abort);
c687bc
- *
c687bc
- * Call a function treating errors as fatal:
c687bc
- *     foo(arg, &error_fatal);
c687bc
- *
c687bc
  * Receive an error and pass it on to the caller:
c687bc
  *     Error *err = NULL;
c687bc
  *     foo(arg, &err;;
c687bc
@@ -86,8 +109,6 @@
c687bc
  *         handle the error...
c687bc
  *         error_propagate(errp, err);
c687bc
  *     }
c687bc
- * where Error **errp is a parameter, by convention the last one.
c687bc
- *
c687bc
  * Do *not* "optimize" this to
c687bc
  *     foo(arg, errp);
c687bc
  *     if (*errp) { // WRONG!
c687bc
-- 
c687bc
2.27.0
c687bc