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,8 +170,9 @@ class Kaylee:
170 170
                 break
171 171
             except queue.Empty:
172 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 177
         self._stop_ui(text)
177 178
 

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

@@ -65,6 +65,10 @@ class Handler:
65 65
 
66 66
         When called, ``tts`` is a function which takes a string as its only
67 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 74
     def __eq__(self, other):
@@ -95,3 +99,7 @@ class Handler:
95 99
             # Intentionally reversed
96 100
             return (self.confidence < other.confidence)
97 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,7 +22,7 @@ but without module-echo-cancel it has almost no chance of working.
22 22
 from gi.repository import GLib
23 23
 from pydbus import SessionBus
24 24
 
25
-from . import PluginBase, Handler
25
+from . import PluginBase, Handler, HandlerFailure
26 26
 
27 27
 
28 28
 class Plugin(PluginBase):
@@ -88,10 +88,7 @@ class MPRISNextHandler(MPRISHandler):
88 88
         try:
89 89
             self.proxy.Next()
90 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 94
 class MPRISPauseHandler(MPRISHandler):
@@ -102,10 +99,7 @@ class MPRISPauseHandler(MPRISHandler):
102 99
         try:
103 100
             self.proxy.Pause()
104 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 105
 class MPRISPlayHandler(MPRISHandler):
@@ -116,10 +110,7 @@ class MPRISPlayHandler(MPRISHandler):
116 110
         try:
117 111
             self.proxy.Play()
118 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 116
 class MPRISPreviousHandler(MPRISHandler):
@@ -130,7 +121,4 @@ class MPRISPreviousHandler(MPRISHandler):
130 121
         try:
131 122
             self.proxy.Previous()
132 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