[gnome-tweaks/improve-error-handling] settings: Implement settings key missing error



commit 92b2d072d2fdfeb34d4e68cf58663fde762e3434
Author: Carlos Soriano <csoriano redhat com>
Date:   Thu Sep 6 14:20:28 2018 +0200

    settings: Implement settings key missing error
    
    Similar to the GSettingsMissingError that is already used, implement
    a custom error for a key missing so it's clearer from where the error
    comes.

 gtweak/gsettings.py | 20 +++++++++++++++++---
 gtweak/widgets.py   |  5 +++--
 2 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/gtweak/gsettings.py b/gtweak/gsettings.py
index e0116e9..d481e88 100644
--- a/gtweak/gsettings.py
+++ b/gtweak/gsettings.py
@@ -19,6 +19,8 @@ _GSETTINGS_RELOCATABLE_SCHEMAS = set(Gio.Settings.list_relocatable_schemas())
 class GSettingsMissingError(Exception):
     pass
 
+class GSettingsKeyMissingError(Exception):
+    pass
 
 class _GSettingsSchema:
     def __init__(self, schema_name, schema_dir=None, schema_filename=None, **options):
@@ -150,13 +152,25 @@ class GSettingsSetting(Gio.Settings):
         return variant.get_type_string() == "as"
 
     def schema_get_summary(self, key):
-        return self._schema._schema[key]["summary"]
+        try:
+            res = self._schema._schema[key]["summary"]
+        except KeyError:
+            raise GSettingsKeyMissingError
+        return res
 
     def schema_get_description(self, key):
-        return self._schema._schema[key]["description"]
+        try:
+            res = self._schema._schema[key]["description"]
+        except KeyError:
+            raise GSettingsKeyMissingError
+        return res
 
     def schema_get_all(self, key):
-        return self._schema._schema[key]
+        try:
+            res = self._schema._schema[key]
+        except KeyError:
+            raise GSettingsKeyMissingError
+        return res
 
     def setting_add_to_list(self, key, value):
         """ helper function, ensures value is present in the GSettingsList at key """
diff --git a/gtweak/widgets.py b/gtweak/widgets.py
index f1d607c..80a9d6a 100644
--- a/gtweak/widgets.py
+++ b/gtweak/widgets.py
@@ -8,7 +8,8 @@ import os.path
 from gi.repository import GLib, Gtk, Gdk, Gio, Pango
 
 from gtweak.tweakmodel import Tweak, TweakGroup
-from gtweak.gsettings import GSettingsSetting, GSettingsFakeSetting, GSettingsMissingError
+from gtweak.gsettings import GSettingsSetting, GSettingsFakeSetting, \
+                             GSettingsMissingError, GSettingsKeyMissingError
 from gtweak.gtksettings import GtkSettingsManager
 from gtweak.gshellwrapper import GnomeShellFactory
 
@@ -135,7 +136,7 @@ class _GSettingsTweak(Tweak):
             Tweak.__init__(self,"","")
             self.loaded = False
             logging.info("GSetting missing %s", e)
-        except KeyError:
+        except GSettingsKeyMissingError:
             self.settings = GSettingsFakeSetting()
             Tweak.__init__(self,"","")
             self.loaded = False


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