eds: Cope with opening buggy EDS address book backends
authorPhilip Withnall <philip@tecnocode.co.uk>
Fri, 6 Jan 2012 23:01:12 +0000 (23:01 +0000)
committerPhilip Withnall <philip@tecnocode.co.uk>
Fri, 6 Jan 2012 23:01:12 +0000 (23:01 +0000)
Turns out that almost as soon as I’d pushed the previous commit, one of my
address books proved me wrong and returned successfully from the async open()
call without being open (according to is_opened()) afterwards. Bother.

This replaces the assertion that the above holds with some code which will
throw an error instead, which should be a bit more robust in the case of
buggy EDS address books.

backends/eds/lib/edsf-persona-store.vala

index ccf44eb..bb63a19 100644 (file)
@@ -689,18 +689,6 @@ public class Edsf.PersonaStore : Folks.PersonaStore
               this._prepare_pending = false;
             }
 
-          // this._addressbook is guaranteed to be non-null by now.
-          if (((!) this._addressbook).is_opened () == false)
-            {
-              /* Remove the persona store on error */
-              this.removed ();
-              this._prepare_pending = false;
-
-              throw new PersonaStoreError.INVALID_ARGUMENT (
-                  /* Translators: the parameter is an address book URI. */
-                  _("Couldn't open address book ‘%s’."), this.id);
-            }
-
           /* Determine which fields the address book supports. This is necessary
            * to work out which writeable properties we can support.
            *
@@ -916,6 +904,8 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   Error? _open_address_book_error = null;
   SourceFunc? _open_address_book_callback = null; /* non-null iff yielded */
 
+  /* Guarantees that either the address book will be open once the method
+   * returns, or an error will be thrown. */
   private async void _open_address_book () throws GLib.Error
     {
       Error? err_out = null;
@@ -976,9 +966,17 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           /* Disconnect the ::opened signal. */
           ((!) this._addressbook).disconnect (signal_id);
 
-          /* Sanity check. */
-          assert (((!) this._addressbook).is_opened () == true ||
-              err_out != null);
+          /* We should really be able to expect that either the address book is
+           * now open, or we have an error set. Unfortunately, this sometimes
+           * isn't the case, probably due to misbehaving EDS backends (though
+           * I haven't investigated). Just throw an error to be on the safe
+           * side. */
+          if (((!) this._addressbook).is_opened () == false && err_out == null)
+            {
+              err_out = new Error (Client.error_quark (),
+                  ClientError.OTHER_ERROR, "Misbehaving EDS backend: %s.",
+                  this.id);
+            }
         }
     }