[gnome-online-accounts] Don't use technical jargon in user visible strings



commit c6457c930cf10c7b72719c47280a73db7a2127d7
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Mar 11 19:05:13 2013 +0100

    Don't use technical jargon in user visible strings
    
    There is no point in telling the user about JSON and the names of the
    various members that we expect to find within it. For the user this is
    just our inability to parse the response.
    
    Detailed explanations with technical terms are better sent to the
    logs.
    
    Fixes: https://bugzilla.gnome.org/657761

 src/goabackend/goafacebookprovider.c    |   22 ++++++++++++++---
 src/goabackend/goaflickrprovider.c      |   28 +++++++++++++++++----
 src/goabackend/goagoogleprovider.c      |   19 ++++++++++++--
 src/goabackend/goaoauth2provider.c      |   24 ++++++++++++++++---
 src/goabackend/goatwitterprovider.c     |   22 ++++++++++++++---
 src/goabackend/goawindowsliveprovider.c |   22 ++++++++++++++---
 src/goabackend/goayahooprovider.c       |   39 ++++++++++++++++++++++++------
 7 files changed, 143 insertions(+), 33 deletions(-)
---
diff --git a/src/goabackend/goafacebookprovider.c b/src/goabackend/goafacebookprovider.c
index 5327df4..b65bf8c 100644
--- a/src/goabackend/goafacebookprovider.c
+++ b/src/goabackend/goafacebookprovider.c
@@ -27,6 +27,7 @@
 #include <rest/rest-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
@@ -164,6 +165,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
                    GCancellable       *cancellable,
                    GError            **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -173,6 +175,8 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -208,9 +212,16 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -218,19 +229,21 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   id = g_strdup (json_object_get_string_member (json_object, "id"));
   if (id == NULL)
     {
+      goa_warning ("Did not find id in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find id member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   presentation_identity = g_strdup (json_object_get_string_member (json_object, "email"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find email in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find email member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -243,6 +256,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (id);
   g_free (presentation_identity);
   if (parser != NULL)
diff --git a/src/goabackend/goaflickrprovider.c b/src/goabackend/goaflickrprovider.c
index 398ae4b..a472669 100644
--- a/src/goabackend/goaflickrprovider.c
+++ b/src/goabackend/goaflickrprovider.c
@@ -28,6 +28,7 @@
 #include <rest/oauth-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauthprovider.h"
@@ -140,6 +141,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
                    GCancellable      *cancellable,
                    GError           **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -149,6 +151,8 @@ get_identity_sync (GoaOAuthProvider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -186,9 +190,16 @@ get_identity_sync (GoaOAuthProvider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -196,37 +207,41 @@ get_identity_sync (GoaOAuthProvider  *provider,
   json_object = json_object_get_object_member (json_object, "user");
   if (json_object == NULL)
     {
+      goa_warning ("Did not find user in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   id = g_strdup (json_object_get_string_member (json_object, "id"));
   if (id == NULL)
     {
+      goa_warning ("Did not find user.id in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user.id member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   json_object = json_object_get_object_member (json_object, "username");
   if (json_object == NULL)
     {
+      goa_warning ("Did not find user.username in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user.username member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   presentation_identity = g_strdup (json_object_get_string_member (json_object, "_content"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find user.username._content in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find user.username._content member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -239,6 +254,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (id);
   g_free (presentation_identity);
   if (call != NULL)
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index fe4200f..3bc174b 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -27,6 +27,7 @@
 #include <rest/oauth-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
@@ -166,6 +167,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
                    GCancellable       *cancellable,
                    GError            **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -174,6 +176,8 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   gchar *email;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -203,9 +207,16 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -213,10 +224,11 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   email = g_strdup (json_object_get_string_member (json_object, "email"));
   if (email == NULL)
     {
+      goa_warning ("Did not find email in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find email member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -227,6 +239,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
     *out_presentation_identity = g_strdup (ret); /* for now: use email as presentation identity */
 
  out:
+  g_clear_error (&identity_error);
   g_free (email);
   if (call != NULL)
     g_object_unref (call);
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index d18d97b..eea3b20 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -579,6 +579,7 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
                  GCancellable       *cancellable,
                  GError            **error)
 {
+  GError *tokens_error;
   RestProxy *proxy;
   RestProxyCall *call;
   gchar *ret;
@@ -595,6 +596,8 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
   ret_access_token_expires_in = 0;
   ret_refresh_token = NULL;
 
+  tokens_error = NULL;
+
   proxy = rest_proxy_new (goa_oauth2_provider_get_token_uri (provider), FALSE);
   call = rest_proxy_new_call (proxy);
 
@@ -643,14 +646,18 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
     {
       GHashTable *hash;
       const gchar *expires_in_str;
+
+      goa_debug ("Response is not JSON - possibly old OAuth2 implementation");
+
       hash = soup_form_decode (payload);
       ret_access_token = g_strdup (g_hash_table_lookup (hash, "access_token"));
       if (ret_access_token == NULL)
         {
+          goa_warning ("Did not find access_token in non-JSON data");
           g_set_error (error,
                        GOA_ERROR,
                        GOA_ERROR_FAILED,
-                       _("Didn't find access_token in non-JSON data"));
+                       _("Could not parse response"));
           g_hash_table_unref (hash);
           goto out;
         }
@@ -671,9 +678,16 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
       JsonObject *object;
 
       parser = json_parser_new ();
-      if (!json_parser_load_from_data (parser, payload, payload_length, error))
+      if (!json_parser_load_from_data (parser, payload, payload_length, &tokens_error))
         {
-          g_prefix_error (error, _("Error parsing response as JSON: "));
+          goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                       tokens_error->message,
+                       g_quark_to_string (tokens_error->domain),
+                       tokens_error->code);
+          g_set_error (error,
+                       GOA_ERROR,
+                       GOA_ERROR_FAILED,
+                       _("Could not parse response"));
           g_object_unref (parser);
           goto out;
         }
@@ -681,10 +695,11 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
       ret_access_token = g_strdup (json_object_get_string_member (object, "access_token"));
       if (ret_access_token == NULL)
         {
+          goa_warning ("Did not find access_token in JSON data");
           g_set_error (error,
                        GOA_ERROR,
                        GOA_ERROR_FAILED,
-                       _("Didn't find access_token in JSON data"));
+                       _("Could not parse response"));
           goto out;
         }
       /* refresh_token is optional... */
@@ -706,6 +721,7 @@ get_tokens_sync (GoaOAuth2Provider  *provider,
     }
 
  out:
+  g_clear_error (&tokens_error);
   g_free (ret_access_token);
   g_free (ret_refresh_token);
   if (call != NULL)
diff --git a/src/goabackend/goatwitterprovider.c b/src/goabackend/goatwitterprovider.c
index affba63..59e0d24 100644
--- a/src/goabackend/goatwitterprovider.c
+++ b/src/goabackend/goatwitterprovider.c
@@ -26,6 +26,7 @@
 #include <rest/oauth-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauthprovider.h"
@@ -126,6 +127,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
                    GCancellable      *cancellable,
                    GError           **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -135,6 +137,8 @@ get_identity_sync (GoaOAuthProvider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -169,9 +173,16 @@ get_identity_sync (GoaOAuthProvider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -179,19 +190,21 @@ get_identity_sync (GoaOAuthProvider  *provider,
   id = g_strdup (json_object_get_string_member (json_object, "id_str"));
   if (id == NULL)
     {
+      goa_warning ("Did not find id_str in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find id_str member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
   presentation_identity = g_strdup (json_object_get_string_member (json_object, "screen_name"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find screen_name in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find screen_name member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -204,6 +217,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (id);
   g_free (presentation_identity);
   if (call != NULL)
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index fd4299b..ed6e3d3 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -29,6 +29,7 @@
 #include <json-glib/json-glib.h>
 #include <webkit/webkit.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
@@ -151,6 +152,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
                    GCancellable       *cancellable,
                    GError            **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -160,6 +162,8 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -190,9 +194,16 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -200,10 +211,11 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   id = g_strdup (json_object_get_string_member (json_object, "id"));
   if (id == NULL)
     {
+      goa_warning ("Did not find id in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find id member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -211,10 +223,11 @@ get_identity_sync (GoaOAuth2Provider  *provider,
   presentation_identity = g_strdup (json_object_get_string_member (json_object, "account"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find emails.account in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find account email member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -227,6 +240,7 @@ get_identity_sync (GoaOAuth2Provider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (id);
   g_free (presentation_identity);
   if (call != NULL)
diff --git a/src/goabackend/goayahooprovider.c b/src/goabackend/goayahooprovider.c
index a414271..ac4b353 100644
--- a/src/goabackend/goayahooprovider.c
+++ b/src/goabackend/goayahooprovider.c
@@ -26,6 +26,7 @@
 #include <rest/oauth-proxy.h>
 #include <json-glib/json-glib.h>
 
+#include "goalogging.h"
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goaoauthprovider.h"
@@ -138,6 +139,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
                    GCancellable      *cancellable,
                    GError           **error)
 {
+  GError *identity_error;
   RestProxy *proxy;
   RestProxyCall *call;
   JsonParser *parser;
@@ -148,6 +150,8 @@ get_identity_sync (GoaOAuthProvider  *provider,
   gchar *presentation_identity;
 
   ret = NULL;
+
+  identity_error = NULL;
   proxy = NULL;
   call = NULL;
   parser = NULL;
@@ -184,9 +188,16 @@ get_identity_sync (GoaOAuthProvider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -194,20 +205,22 @@ get_identity_sync (GoaOAuthProvider  *provider,
   json_data_object = json_object_get_object_member (json_object, "guid");
   if (json_data_object == NULL)
     {
+      goa_warning ("Did not find guid in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find guid member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
   guid = g_strdup (json_object_get_string_member (json_data_object, "value"));
   if (guid == NULL)
     {
+      goa_warning ("Did not find value in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find value member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -244,9 +257,16 @@ get_identity_sync (GoaOAuthProvider  *provider,
   if (!json_parser_load_from_data (parser,
                                    rest_proxy_call_get_payload (call),
                                    rest_proxy_call_get_payload_length (call),
-                                   error))
+                                   &identity_error))
     {
-      g_prefix_error (error, _("Error parsing usercard response as JSON: "));
+      goa_warning ("json_parser_load_from_data() failed: %s (%s, %d)",
+                   identity_error->message,
+                   g_quark_to_string (identity_error->domain),
+                   identity_error->code);
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -254,20 +274,22 @@ get_identity_sync (GoaOAuthProvider  *provider,
   json_data_object = json_object_get_object_member (json_object, "profile");
   if (json_data_object == NULL)
     {
+      goa_warning ("Did not find profile in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find profile member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
   presentation_identity = g_strdup (json_object_get_string_member (json_data_object, "nickname"));
   if (presentation_identity == NULL)
     {
+      goa_warning ("Did not find nickname in JSON data");
       g_set_error (error,
                    GOA_ERROR,
                    GOA_ERROR_FAILED,
-                   _("Didn't find nickname member in JSON data"));
+                   _("Could not parse response"));
       goto out;
     }
 
@@ -280,6 +302,7 @@ get_identity_sync (GoaOAuthProvider  *provider,
     }
 
  out:
+  g_clear_error (&identity_error);
   g_free (presentation_identity);
   g_free (guid);
   if (call != NULL)


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