]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
util/error: make func optional
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 28 May 2025 12:27:47 +0000 (14:27 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 5 Jun 2025 18:24:51 +0000 (20:24 +0200)
The function name is not available in Rust, so make it optional.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/qapi/error-internal.h
util/error.c

index 1ec3ceb40f0ec42914596ca8d5d253e03c7cc89d..ff18a2086d257f23d1399b8ffdc592c099a4be7e 100644 (file)
@@ -18,6 +18,8 @@ struct Error
 {
     char *msg;
     ErrorClass err_class;
+
+    /* Used for error_abort only, may be NULL. */
     const char *func;
 
     /*
index 3449ecc0b92a4a0498a432c8a83faf632b412ebe..daea2142f30121abc46e5342526f5eec40ea246e 100644 (file)
@@ -24,8 +24,13 @@ Error *error_warn;
 static void error_handle(Error **errp, Error *err)
 {
     if (errp == &error_abort) {
-        fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n",
-                err->func, err->src_len, err->src, err->line);
+        if (err->func) {
+            fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n",
+                    err->func, err->src_len, err->src, err->line);
+        } else {
+            fprintf(stderr, "Unexpected error at %.*s:%d:\n",
+                   err->src_len, err->src, err->line);
+        }
         error_report("%s", error_get_pretty(err));
         if (err->hint) {
             error_printf("%s", err->hint->str);