[glib] gdbus-tool: avoid irrelevant note about arg types



commit 05060b6194be6bedecac64f7974e36f2770628a8
Author: Allison Ryan Lortie <desrt desrt ca>
Date:   Thu Apr 28 10:48:00 2016 +0200

    gdbus-tool: avoid irrelevant note about arg types
    
    gdbus-tool prints a hint about the expected arguments to a function call
    in case of errors.  Unfortunately, it prints this message on all errors.
    I've seen this confuse users several times -- they go on tweaking the
    arguments trying to get the correct type, even though they had it
    correct in the first place.
    
    Let's limit the hint to the case where it was actually invalid arguments
    that triggered the problem.  Also, adjust the code that prints the
    message so that it will also report on the case that no arguments were
    expected.
    
    We could possibly get closer to what we want by comparing the list of
    expected arguments with the parameter list, as it was parsed from the
    user, but that would involve composing the expected type.  Let's keep
    this simple for now.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765710

 gio/gdbus-tool.c |   36 +++++++++++++++++++++---------------
 1 files changed, 21 insertions(+), 15 deletions(-)
---
diff --git a/gio/gdbus-tool.c b/gio/gdbus-tool.c
index c021f48..d59cbbf 100644
--- a/gio/gdbus-tool.c
+++ b/gio/gdbus-tool.c
@@ -1038,25 +1038,31 @@ handle_call (gint        *argc,
                                         &error);
   if (result == NULL)
     {
-      if (error)
-        {
-          g_printerr (_("Error: %s\n"), error->message);
-          g_error_free (error);
-        }
-      if (in_signature_types != NULL)
+      g_printerr (_("Error: %s\n"), error->message);
+
+      if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS) && in_signature_types != NULL)
         {
-          GString *s;
-          s = g_string_new (NULL);
-          for (n = 0; n < in_signature_types->len; n++)
+          if (in_signature_types->len > 0)
             {
-              GVariantType *type = in_signature_types->pdata[n];
-              g_string_append_len (s,
-                                   g_variant_type_peek_string (type),
-                                   g_variant_type_get_string_length (type));
+              GString *s;
+              s = g_string_new (NULL);
+
+              for (n = 0; n < in_signature_types->len; n++)
+                {
+                  GVariantType *type = in_signature_types->pdata[n];
+                  g_string_append_len (s,
+                                       g_variant_type_peek_string (type),
+                                       g_variant_type_get_string_length (type));
+                }
+
+              g_printerr ("(According to introspection data, you need to pass '%s')\n", s->str);
+              g_string_free (s, TRUE);
             }
-          g_printerr ("(According to introspection data, you need to pass '%s')\n", s->str);
-          g_string_free (s, TRUE);
+          else
+            g_printerr ("(According to introspection data, you need to pass no arguments)\n");
         }
+
+      g_error_free (error);
       goto out;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]