yeahuh / rpms / qemu-kvm

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