|
|
709dde |
From b41fc6d57fae80ac2a431bca22862985f003fe88 Mon Sep 17 00:00:00 2001
|
|
|
709dde |
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
|
|
|
709dde |
Date: Fri, 8 Jan 2021 07:40:54 -0500
|
|
|
709dde |
Subject: [PATCH 03/10] 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>
|
|
|
709dde |
Message-id: <20210108074101.290008-4-marcandre.lureau@redhat.com>
|
|
|
709dde |
Patchwork-id: 100522
|
|
|
709dde |
O-Subject: [RHEL-8.3.0.z qemu-kvm PATCH 03/10] error: Improve error.h's big comment
|
|
|
709dde |
Bugzilla: 1913818
|
|
|
709dde |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
709dde |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
709dde |
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
|
|
|
709dde |
|
|
|
709dde |
From: Marc-André Lureau <marcandre.lureau@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 |
|