[gnome-games/wip/exalm/uid: 3/16] uid: Don't throw errors for get_uid()



commit 59139de17b6bcac50c21200ddf726f487965424e
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Mar 5 22:32:34 2020 +0500

    uid: Don't throw errors for get_uid()

 src/core/cover-loader.vala    | 11 ++---------
 src/core/game-collection.vala | 26 ++++----------------------
 src/core/game-model.vala      | 11 +++--------
 src/core/game.vala            | 25 +++----------------------
 src/core/uid.vala             |  2 +-
 5 files changed, 13 insertions(+), 62 deletions(-)
---
diff --git a/src/core/cover-loader.vala b/src/core/cover-loader.vala
index 7b697814..f58ac002 100644
--- a/src/core/cover-loader.vala
+++ b/src/core/cover-loader.vala
@@ -112,7 +112,7 @@ public class Games.CoverLoader : Object {
                }
        }
 
-       private string get_cache_path (Game game, int size, string dir_name) throws Error {
+       private string get_cache_path (Game game, int size, string dir_name) {
                var dir = Application.get_image_cache_dir (dir_name, size);
 
                var uid = game.get_uid ().get_uid ();
@@ -121,14 +121,7 @@ public class Games.CoverLoader : Object {
        }
 
        private Gdk.Pixbuf? load_cache_from_disk (Game game, int size, string dir) {
-               string cache_path;
-               try {
-                       cache_path = get_cache_path (game, size, dir);
-               }
-               catch (Error e) {
-                       critical (e.message);
-                       return null;
-               }
+               var cache_path = get_cache_path (game, size, dir);
 
                try {
                        return new Gdk.Pixbuf.from_file (cache_path);
diff --git a/src/core/game-collection.vala b/src/core/game-collection.vala
index 2fdd8abb..f1896813 100644
--- a/src/core/game-collection.vala
+++ b/src/core/game-collection.vala
@@ -103,11 +103,7 @@ private class Games.GameCollection : Object {
                                        database.list_cached_games ((game) => {
                                                cached_games[game.get_uri ().to_string ()] = game;
 
-                                               string? uid = null;
-                                               try {
-                                                       uid = game.get_uid ().get_uid ();
-                                               }
-                                               catch (Error e) {}
+                                               var uid = game.get_uid ().get_uid ();
 
                                                if (games.contains (uid))
                                                        return;
@@ -150,11 +146,7 @@ private class Games.GameCollection : Object {
                                        warning ("Couldn't remove game: %s", e.message);
                                }
 
-                               string? uid = null;
-                               try {
-                                       uid = game.get_uid ().get_uid ();
-                               }
-                               catch (Error e) {}
+                               var uid = game.get_uid ().get_uid ();
 
                                games.remove (uid);
                                if (removed)
@@ -275,11 +267,7 @@ private class Games.GameCollection : Object {
                        warning ("Couldn't cache game: %s", e.message);
                }
 
-               string? uid = null;
-               try {
-                       uid = game.get_uid ().get_uid ();
-               }
-               catch (Error e) {}
+               var uid = game.get_uid ().get_uid ();
 
                if (games.contains (uid) && prev_game == null)
                        return;
@@ -307,13 +295,7 @@ private class Games.GameCollection : Object {
                ulong loading_done_id = 0;
 
                game_added_id = game_added.connect ((game) => {
-                       string? game_uid = null;
-                       try {
-                               game_uid = game.get_uid ().get_uid ();
-                       }
-                       catch (Error e) {
-                               return;
-                       }
+                       var game_uid = game.get_uid ().get_uid ();
 
                        if (game_uid != uid)
                                return;
diff --git a/src/core/game-model.vala b/src/core/game-model.vala
index c19d9e12..65e6495c 100644
--- a/src/core/game-model.vala
+++ b/src/core/game-model.vala
@@ -67,14 +67,9 @@ private class Games.GameModel : Object, ListModel {
                if (ret != 0)
                        return ret;
 
-               try {
-                       var uid1 = a.get_uid ().get_uid ();
-                       var uid2 = b.get_uid ().get_uid ();
+               var uid1 = a.get_uid ().get_uid ();
+               var uid2 = b.get_uid ().get_uid ();
 
-                       return uid1.collate (uid2);
-               }
-               catch (Error e) {
-                       assert_not_reached ();
-               }
+               return uid1.collate (uid2);
        }
 }
diff --git a/src/core/game.vala b/src/core/game.vala
index 722b32be..afb499ce 100644
--- a/src/core/game.vala
+++ b/src/core/game.vala
@@ -87,13 +87,7 @@ public class Games.Game : Object {
        }
 
        public static uint hash (Game key) {
-               var uid = "";
-               try {
-                       uid = key.get_uid ().get_uid ();
-               }
-               catch (Error e) {
-                       critical (e.message);
-               }
+               var uid = key.get_uid ().get_uid ();
 
                return str_hash (uid);
        }
@@ -102,21 +96,8 @@ public class Games.Game : Object {
                if (direct_equal (a, b))
                        return true;
 
-               var a_uid = "";
-               try {
-                       a_uid = a.get_uid ().get_uid ();
-               }
-               catch (Error e) {
-                       critical (e.message);
-               }
-
-               var b_uid = "";
-               try {
-                       b_uid = b.get_uid ().get_uid ();
-               }
-               catch (Error e) {
-                       critical (e.message);
-               }
+               var a_uid = a.get_uid ().get_uid ();
+               var b_uid = b.get_uid ().get_uid ();
 
                return str_equal (a_uid, b_uid);
        }
diff --git a/src/core/uid.vala b/src/core/uid.vala
index 5ae18aa1..4e9250d7 100644
--- a/src/core/uid.vala
+++ b/src/core/uid.vala
@@ -7,7 +7,7 @@ public class Games.Uid : Object {
                this.uid = uid;
        }
 
-       public string get_uid () throws Error {
+       public string get_uid () {
                return uid;
        }
 }


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