[geary] Fix crash when parsing unknown accout info service provider. Bug 713985.



commit 83955b3d5841821b9661ae079e94011512da273f
Author: Michael James Gratton <mike vee net>
Date:   Sat Jul 30 11:18:26 2016 +1000

    Fix crash when parsing unknown accout info  service provider. Bug 713985.
    
    * src/engine/api/geary-service-provider.vala
      (ServiceProvider::from_string): Throw an error rather than an assert
      when the provided string is not found.

 src/engine/api/geary-service-provider.vala |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/api/geary-service-provider.vala b/src/engine/api/geary-service-provider.vala
index 8eba36f..574b874 100644
--- a/src/engine/api/geary-service-provider.vala
+++ b/src/engine/api/geary-service-provider.vala
@@ -64,14 +64,16 @@ public enum Geary.ServiceProvider {
                 assert_not_reached();
         }
     }
-    
+
     /**
-     * Converts a string form of the service provider (returned by {@link to_string} to a
-     * {@link ServiceProvider} value.
+     * Converts a string form of the service provider (returned by
+     * {@link to_string} to a {@link ServiceProvider} value.
+     *
+     * Throws an error if the string is not valid.
      *
      * @see to_string
      */
-    public static ServiceProvider from_string(string str) {
+    public static ServiceProvider from_string(string str) throws Error {
         switch (str.up()) {
             case "GMAIL":
                 return GMAIL;
@@ -84,9 +86,14 @@ public enum Geary.ServiceProvider {
             
             case "OTHER":
                 return OTHER;
-            
+
             default:
-                assert_not_reached();
+                // Could use a better errordomain here, but for now
+                // this only gets used when parsing keyfiles in
+                // AccountInfo.
+                throw new KeyFileError.INVALID_VALUE(
+                    "Unknown service provider type: %s", str
+                );
         }
     }
 }


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