Bug 664072 — Folks should only use assert*() for critical, program-terminating errors
authorPhilip Withnall <philip@tecnocode.co.uk>
Mon, 30 Jul 2012 10:03:21 +0000 (12:03 +0200)
committerPhilip Withnall <philip@tecnocode.co.uk>
Thu, 16 Aug 2012 23:03:12 +0000 (00:03 +0100)
Turn various assert()s into return[_val]_if_fail()s.

Closes: https://bugzilla.gnome.org/show_bug.cgi?id=664072

NEWS
backends/telepathy/lib/tpf-persona-store.vala
folks/individual.vala
folks/potential-match.vala

diff --git a/NEWS b/NEWS
index 9fc2d2a..065a869 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ Bugs fixed:
 • Bug 681346 — Individual id can be inconsistent
 • Bug 681420 — warning (vala 0.17.x): access to static class members through an
   instance variable
+• Bug 664072 — Folks should only use assert*() for critical, program-terminating
+  errors
 
 Overview of changes from libfolks 0.7.2 to libfolks 0.7.3
 =========================================================
index bbff7c3..3fb9809 100644 (file)
@@ -1554,7 +1554,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
             }
 
           /* Bail if a store already exists for this account. */
-          assert (!PersonaStore._persona_stores_by_account.has_key (store.id));
+          return_if_fail (
+              !PersonaStore._persona_stores_by_account.has_key (store.id));
 
           /* Add the store. */
           PersonaStore._persona_stores_by_account.set (store.id, store);
index d0bd428..e087b25 100644 (file)
@@ -1258,8 +1258,8 @@ public class Folks.Individual : Object,
     {
       CompareDataFunc<Persona> primary_compare_func = (a, b) =>
         {
-          assert (a != null);
-          assert (b != null);
+          return_val_if_fail (a != null, 0);
+          return_val_if_fail (b != null, 0);
 
           /* Always prefer values which are set over those which aren't. */
           var a_is_set = filter_func (a);
@@ -1446,7 +1446,7 @@ public class Folks.Individual : Object,
       this._update_single_valued_property (typeof (AliasDetails), (p) =>
         {
           var alias = ((AliasDetails) p).alias;
-          assert (alias != null);
+          return_val_if_fail (alias != null, false);
 
           return (alias.strip () != ""); /* empty aliases are unset */
         }, (a, b) =>
@@ -1454,8 +1454,8 @@ public class Folks.Individual : Object,
           var a_alias = ((AliasDetails) a).alias;
           var b_alias = ((AliasDetails) b).alias;
 
-          assert (a_alias != null);
-          assert (b_alias != null);
+          return_val_if_fail (a_alias != null, 0);
+          return_val_if_fail (b_alias != null, 0);
 
           var a_is_empty = (a_alias.strip () == "") ? 1 : 0;
           var b_is_empty = (b_alias.strip () == "") ? 1 : 0;
@@ -1670,7 +1670,7 @@ public class Folks.Individual : Object,
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
           var name = ((NameDetails) p).full_name;
-          assert (name != null);
+          return_val_if_fail (name != null, false);
 
           return (name.strip () != ""); /* empty names are unset */
         }, (a, b) =>
@@ -1699,7 +1699,7 @@ public class Folks.Individual : Object,
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
           var nickname = ((NameDetails) p).nickname;
-          assert (nickname != null);
+          return_val_if_fail (nickname != null, false);
 
           return (nickname.strip () != ""); /* empty names are unset */
         }, (a, b) =>
index aa58df9..31eac72 100644 (file)
@@ -473,8 +473,8 @@ public class Folks.PotentialMatch : Object
           return false;
         }
 
-      assert (a.validate ());
-      assert (b.validate ());
+      return_val_if_fail (a.validate (), false);
+      return_val_if_fail (b.validate (), false);
 
       var a_stripped = this._strip_string ((!) a);
       var b_stripped = this._strip_string ((!) b);
@@ -499,8 +499,8 @@ public class Folks.PotentialMatch : Object
           return false;
         }
 
-      assert (a.validate ());
-      assert (b.validate ());
+      return_val_if_fail (a.validate (), false);
+      return_val_if_fail (b.validate (), false);
 
       var a_stripped = this._strip_string ((!) a);
       var b_stripped = this._strip_string ((!) b);