Browse Source

Added the HandlerFailure exception

Clara Hobbs 6 years ago
parent
commit
7bde854966
3 changed files with 16 additions and 19 deletions
  1. 3
    2
      kayleevc/kaylee.py
  2. 8
    0
      kayleevc/plugins/__init__.py
  3. 5
    17
      kayleevc/plugins/mpris.py

+ 3
- 2
kayleevc/kaylee.py View File

170
                 break
170
                 break
171
             except queue.Empty:
171
             except queue.Empty:
172
                 break
172
                 break
173
-                # If an unknown error occurs, ignore it and keep trying
174
-                # FIXME not a good API decision
173
+            except kayleevc.plugins.HandlerFailure:
174
+                # If the handler failed, keep trying
175
+                continue
175
 
176
 
176
         self._stop_ui(text)
177
         self._stop_ui(text)
177
 
178
 

+ 8
- 0
kayleevc/plugins/__init__.py View File

65
 
65
 
66
         When called, ``tts`` is a function which takes a string as its only
66
         When called, ``tts`` is a function which takes a string as its only
67
         parameter and passes it to Kaylee's configured text-to-speech system.
67
         parameter and passes it to Kaylee's configured text-to-speech system.
68
+
69
+        If command handling fails for some reason that can be anticipated, this
70
+        method must raise a HandlerFailure to tell Kaylee to keep trying other
71
+        handlers.
68
         """
72
         """
69
 
73
 
70
     def __eq__(self, other):
74
     def __eq__(self, other):
95
             # Intentionally reversed
99
             # Intentionally reversed
96
             return (self.confidence < other.confidence)
100
             return (self.confidence < other.confidence)
97
         return NotImplemented
101
         return NotImplemented
102
+
103
+
104
+class HandlerFailure(Exception):
105
+    """Handler failed to handle its command."""

+ 5
- 17
kayleevc/plugins/mpris.py View File

22
 from gi.repository import GLib
22
 from gi.repository import GLib
23
 from pydbus import SessionBus
23
 from pydbus import SessionBus
24
 
24
 
25
-from . import PluginBase, Handler
25
+from . import PluginBase, Handler, HandlerFailure
26
 
26
 
27
 
27
 
28
 class Plugin(PluginBase):
28
 class Plugin(PluginBase):
88
         try:
88
         try:
89
             self.proxy.Next()
89
             self.proxy.Next()
90
         except GLib.Error:
90
         except GLib.Error:
91
-            # This error is raised if the media player was closed after we got
92
-            # the proxy but before we called next.
93
-            # FIXME raise a different exception to tell Kaylee that we failed
94
-            pass
91
+            raise HandlerFailure()
95
 
92
 
96
 
93
 
97
 class MPRISPauseHandler(MPRISHandler):
94
 class MPRISPauseHandler(MPRISHandler):
102
         try:
99
         try:
103
             self.proxy.Pause()
100
             self.proxy.Pause()
104
         except GLib.Error:
101
         except GLib.Error:
105
-            # This error is raised if the media player was closed after we got
106
-            # the proxy but before we called pause.
107
-            # FIXME raise a different exception to tell Kaylee that we failed
108
-            pass
102
+            raise HandlerFailure()
109
 
103
 
110
 
104
 
111
 class MPRISPlayHandler(MPRISHandler):
105
 class MPRISPlayHandler(MPRISHandler):
116
         try:
110
         try:
117
             self.proxy.Play()
111
             self.proxy.Play()
118
         except GLib.Error:
112
         except GLib.Error:
119
-            # This error is raised if the media player was closed after we got
120
-            # the proxy but before we called play.
121
-            # FIXME raise a different exception to tell Kaylee that we failed
122
-            pass
113
+            raise HandlerFailure()
123
 
114
 
124
 
115
 
125
 class MPRISPreviousHandler(MPRISHandler):
116
 class MPRISPreviousHandler(MPRISHandler):
130
         try:
121
         try:
131
             self.proxy.Previous()
122
             self.proxy.Previous()
132
         except GLib.Error:
123
         except GLib.Error:
133
-            # This error is raised if the media player was closed after we got
134
-            # the proxy but before we called previous.
135
-            # FIXME raise a different exception to tell Kaylee that we failed
136
-            pass
124
+            raise HandlerFailure()

Loading…
Cancel
Save