[PATCH 06/12] util/error: make func optional

Paolo Bonzini posted 12 patches 5 months, 3 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
There is a newer version of this series
[PATCH 06/12] util/error: make func optional
Posted by Paolo Bonzini 5 months, 3 weeks ago
The function name is not available in Rust, so make it optional.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 util/error.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/util/error.c b/util/error.c
index 6c1033eaba5..b977007faaf 100644
--- a/util/error.c
+++ b/util/error.c
@@ -29,8 +29,12 @@ static void error_handle(Error **errp, Error *err)
             /* No need to free it, the program will abort very soon...  */
             src = g_strndup(err->src, err->src_len);
         }
-        fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
-                err->func, src, err->line);
+        if (err->func) {
+            fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
+                    err->func, src, err->line);
+        } else {
+            fprintf(stderr, "Unexpected error at %s:%d:\n", src, err->line);
+        }
         error_report("%s", error_get_pretty(err));
         if (err->hint) {
             error_printf("%s", err->hint->str);
-- 
2.49.0
Re: [PATCH 06/12] util/error: make func optional
Posted by Zhao Liu 5 months, 3 weeks ago
On Mon, May 26, 2025 at 04:24:49PM +0200, Paolo Bonzini wrote:
> Date: Mon, 26 May 2025 16:24:49 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 06/12] util/error: make func optional
> X-Mailer: git-send-email 2.49.0
> 
> The function name is not available in Rust, so make it optional.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  util/error.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

panic::Location does not provide function name information. Although
there are macros that could print function names [*] (as I'm sure you've
noticed :) ), that way - printing the information based on some macros -
would definitely require some wrapping or modification of Err().

Comparing with that, current implementation looks better in general.

[*]: https://stackoverflow.com/a/63904992/24336517

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>