[gedit-plugins] Catch GLib.Error when possible instead of Exception



commit fd17928e4271d7bf62a034b72143f31636facc66
Author: Garrett Regier <garrettregier gmail com>
Date:   Sun Jun 29 14:03:05 2014 -0700

    Catch GLib.Error when possible instead of Exception
    
    This can hide problems and make debugging difficult.

 plugins/git/git/appactivatable.py  |   33 +++++++++++++++------------------
 plugins/git/git/viewactivatable.py |    2 +-
 2 files changed, 16 insertions(+), 19 deletions(-)
---
diff --git a/plugins/git/git/appactivatable.py b/plugins/git/git/appactivatable.py
index 2dc6cc3..7c41e68 100644
--- a/plugins/git/git/appactivatable.py
+++ b/plugins/git/git/appactivatable.py
@@ -62,31 +62,28 @@ class GitAppActivatable(GObject.Object, Gedit.AppActivatable):
         # Must check every dir, otherwise submodules will have issues
         try:
             repo_file = Ggit.Repository.discover(location)
-            repo_uri = repo_file.get_parent().get_uri()
 
-            # Reuse the repo if requested multiple times
-            try:
-                repo = self.__repos[repo_uri]
+        except GLib.Error:
+            return None
+
+        repo_uri = repo_file.get_parent().get_uri()
 
-            except KeyError:
-                repo = Ggit.Repository.open(repo_file)
+        # Reuse the repo if requested multiple times
+        try:
+            repo = self.__repos[repo_uri]
 
-                # TODO: this was around even when not used, on purpose?
-                head = repo.get_head()
-                commit = repo.lookup(head.get_target(),
-                                     Ggit.Commit.__gtype__)
-                tree = commit.get_tree()
+        except KeyError:
+            repo = Ggit.Repository.open(repo_file)
 
-                self.__repos[repo_uri] = repo
-                self.__repos[repo.get_workdir().get_uri()] = repo
-                #print(repo.get_workdir().get_uri())
+            # TODO: this was around even when not used, on purpose?
+            head = repo.get_head()
+            commit = repo.lookup(head.get_target(), Ggit.Commit.__gtype__)
+            tree = commit.get_tree()
 
-        except Exception:
-            return None
+            self.__repos[repo_uri] = repo
+            self.__repos[repo.get_workdir().get_uri()] = repo
 
         while dir_uri not in self.__repos:
-            #print(dir_uri)
-
             self.__repos[dir_uri] = repo
             dir_location = dir_location.get_parent()
             dir_uri = dir_location.get_uri()
diff --git a/plugins/git/git/viewactivatable.py b/plugins/git/git/viewactivatable.py
index f3a4173..68ba6c8 100644
--- a/plugins/git/git/viewactivatable.py
+++ b/plugins/git/git/viewactivatable.py
@@ -140,7 +140,7 @@ class GitViewActivatable(GObject.Object, Gedit.ViewActivatable):
             if last_item[-1:] == '\n':
                 self.file_contents_list[-1] = last_item[:-1]
 
-        except Exception:
+        except GLib.Error:
             # New file in a git repository
             self.file_contents_list = []
 


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