[PATCH] virJSONValueFromString: Prefix error message from 'json-c'

Peter Krempa posted 1 patch 7 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/6be1287a5259e094f888311e230be0cbf5b70fa0.1729865842.git.pkrempa@redhat.com
src/util/virjson.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] virJSONValueFromString: Prefix error message from 'json-c'
Posted by Peter Krempa 7 months, 3 weeks ago
The error message from 'json-c' was passed along without any libvirt
string which makes it hard to find in the source and isn't exactly clear
when present in logs:

 libvirtd[843]: internal error : invalid utf-8 string

Prefix the message with 'failed to parse JSON'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/util/virjson.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index 42018a98b4..4a95e84f5b 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1467,7 +1467,8 @@ virJSONValueFromString(const char *jsonstring)
     jerr = json_tokener_get_error(tok);
     if (jerr != json_tokener_success) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", json_tokener_error_desc(jerr));
+                       _("failed to parse JSON: %1$s"),
+                       json_tokener_error_desc(jerr));
         goto cleanup;
     }
     ret = virJSONValueFromJsonC(jobj);
-- 
2.47.0
Re: [PATCH] virJSONValueFromString: Prefix error message from 'json-c'
Posted by Daniel P. Berrangé 7 months, 3 weeks ago
On Fri, Oct 25, 2024 at 04:17:22PM +0200, Peter Krempa wrote:
> The error message from 'json-c' was passed along without any libvirt
> string which makes it hard to find in the source and isn't exactly clear
> when present in logs:
> 
>  libvirtd[843]: internal error : invalid utf-8 string
> 
> Prefix the message with 'failed to parse JSON'.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/util/virjson.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|