[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 05/25] error: add global &error_warn destination
From: |
marcandre . lureau |
Subject: |
[PULL v2 05/25] error: add global &error_warn destination |
Date: |
Mon, 13 Mar 2023 15:46:28 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
This can help debugging issues or develop, when error handling is
introduced.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Message-Id: <20230221124802.4103554-6-marcandre.lureau@redhat.com>
---
include/qapi/error.h | 6 ++++++
tests/unit/test-error-report.c | 18 ++++++++++++++++++
util/error.c | 10 +++++++---
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/include/qapi/error.h b/include/qapi/error.h
index d798faeec3..f21a231bb1 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -519,6 +519,12 @@ static inline void
error_propagator_cleanup(ErrorPropagator *prop)
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
+/*
+ * Special error destination to warn on error.
+ * See error_setg() and error_propagate() for details.
+ */
+extern Error *error_warn;
+
/*
* Special error destination to abort on error.
* See error_setg() and error_propagate() for details.
diff --git a/tests/unit/test-error-report.c b/tests/unit/test-error-report.c
index b09650687b..54319c86c9 100644
--- a/tests/unit/test-error-report.c
+++ b/tests/unit/test-error-report.c
@@ -12,6 +12,7 @@
#include <locale.h>
#include "qemu/error-report.h"
+#include "qapi/error.h"
static void
test_error_report_simple(void)
@@ -103,6 +104,22 @@ test_error_report_timestamp(void)
");
}
+static void
+test_error_warn(void)
+{
+ if (g_test_subprocess()) {
+ error_setg(&error_warn, "Testing &error_warn");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report: warning: Testing &error_warn*\
+");
+}
+
+
int
main(int argc, char *argv[])
{
@@ -116,6 +133,7 @@ main(int argc, char *argv[])
g_test_add_func("/error-report/glog", test_error_report_glog);
g_test_add_func("/error-report/once", test_error_report_once);
g_test_add_func("/error-report/timestamp", test_error_report_timestamp);
+ g_test_add_func("/error-report/warn", test_error_warn);
return g_test_run();
}
diff --git a/util/error.c b/util/error.c
index 1e7af665b8..5537245da6 100644
--- a/util/error.c
+++ b/util/error.c
@@ -27,8 +27,9 @@ struct Error
Error *error_abort;
Error *error_fatal;
+Error *error_warn;
-static void error_handle_fatal(Error **errp, Error *err)
+static void error_handle(Error **errp, Error *err)
{
if (errp == &error_abort) {
fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
@@ -43,6 +44,9 @@ static void error_handle_fatal(Error **errp, Error *err)
error_report_err(err);
exit(1);
}
+ if (errp == &error_warn) {
+ warn_report_err(err);
+ }
}
G_GNUC_PRINTF(6, 0)
@@ -71,7 +75,7 @@ static void error_setv(Error **errp,
err->line = line;
err->func = func;
- error_handle_fatal(errp, err);
+ error_handle(errp, err);
*errp = err;
errno = saved_errno;
@@ -284,7 +288,7 @@ void error_propagate(Error **dst_errp, Error *local_err)
if (!local_err) {
return;
}
- error_handle_fatal(dst_errp, local_err);
+ error_handle(dst_errp, local_err);
if (dst_errp && !*dst_errp) {
*dst_errp = local_err;
} else {
--
2.39.2
- [PULL v2 00/25] Win socket patches, marcandre . lureau, 2023/03/13
- [PULL v2 01/25] util: drop qemu_fork(), marcandre . lureau, 2023/03/13
- [PULL v2 02/25] tests: use closesocket(), marcandre . lureau, 2023/03/13
- [PULL v2 03/25] io: use closesocket(), marcandre . lureau, 2023/03/13
- [PULL v2 04/25] tests: add test-error-report, marcandre . lureau, 2023/03/13
- [PULL v2 06/25] win32/socket: introduce qemu_socket_select() helper, marcandre . lureau, 2023/03/13
- [PULL v2 07/25] win32/socket: introduce qemu_socket_unselect() helper, marcandre . lureau, 2023/03/13
- [PULL v2 05/25] error: add global &error_warn destination,
marcandre . lureau <=
- [PULL v2 08/25] aio: make aio_set_fd_poll() static to aio-posix.c, marcandre . lureau, 2023/03/13
- [PULL v2 09/25] aio/win32: aio_set_fd_handler() only supports SOCKET, marcandre . lureau, 2023/03/13
- [PULL v2 10/25] main-loop: remove qemu_fd_register(), win32/slirp/socket specific, marcandre . lureau, 2023/03/13
- [PULL v2 11/25] slirp: unregister the win32 SOCKET, marcandre . lureau, 2023/03/13
- [PULL v2 12/25] slirp: open-code qemu_socket_(un)select(), marcandre . lureau, 2023/03/13
- [PULL v2 14/25] os-posix: remove useless ioctlsocket() define, marcandre . lureau, 2023/03/13
- [PULL v2 15/25] win32: replace closesocket() with close() wrapper, marcandre . lureau, 2023/03/13
- [PULL v2 13/25] win32: avoid mixing SOCKET and file descriptor space, marcandre . lureau, 2023/03/13
- [PULL v2 17/25] char: do not double-close fd when failing to add client, marcandre . lureau, 2023/03/13
- [PULL v2 19/25] osdep: implement qemu_socketpair() for win32, marcandre . lureau, 2023/03/13