Skip to content

Commit 0a7c894

Browse files
author
brentru
committed
handle keyerror
1 parent a8b1af9 commit 0a7c894

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ def add_topic_callback(self, mqtt_topic, callback_method):
227227
:param str callback_method: Name of callback method.
228228
229229
"""
230-
print("adding topic callback...")
231230
if mqtt_topic is None or callback_method is None:
232231
raise ValueError("MQTT topic and callback method must both be defined.")
233232
self._on_message_filtered[mqtt_topic] = callback_method
@@ -239,7 +238,10 @@ def remove_topic_callback(self, mqtt_topic):
239238
"""
240239
if mqtt_topic is None:
241240
raise ValueError("MQTT Topic must be defined.")
242-
del self._on_message_filtered[mqtt_topic]
241+
try:
242+
del self._on_message_filtered[mqtt_topic]
243+
except KeyError:
244+
raise KeyError("MQTT topic callback not added with add_topic_callback.")
243245

244246
@property
245247
def on_message(self):

0 commit comments

Comments
 (0)