Skip to content

Commit 1cd2964

Browse files
committed
Log exceptions during handling in Text interfaces.
1 parent cb73660 commit 1cd2964

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

paradox/interfaces/text/core.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from paradox.event import Event, EventLevel, Notification
55
from paradox.interfaces import ThreadQueueInterface
66
from paradox.lib import ps
7-
from paradox.lib.event_filter import (EventFilter, EventTagFilter,
8-
LiveEventRegexpFilter)
7+
from paradox.lib.event_filter import EventFilter, EventTagFilter, LiveEventRegexpFilter
98

109
logger = logging.getLogger("PAI").getChild(__name__)
1110

@@ -25,7 +24,7 @@ def stop(self):
2524
super().stop()
2625

2726
def _run(self):
28-
super(AbstractTextInterface, self)._run()
27+
super()._run()
2928

3029
ps.subscribe(self.handle_panel_event, "events")
3130
ps.subscribe(self.handle_notify, "notifications")
@@ -38,19 +37,25 @@ def notification_filter(self, notification: Notification):
3837

3938
def handle_notify(self, notification: Notification):
4039
if self.notification_filter(notification):
41-
self.send_message(notification.message, notification.level)
40+
try:
41+
self.send_message(notification.message, notification.level)
42+
except Exception as e:
43+
logger.exception(f"Error handling notification: {e}")
4244

4345
def handle_panel_event(self, event: Event):
4446
if self.event_filter.match(event):
45-
self.send_message(event.message, event.level)
47+
try:
48+
self.send_message(event.message, event.level)
49+
except Exception as e:
50+
logger.exception(f"Error handling event: {e}")
4651

4752
async def handle_command(self, message_raw):
4853
message = cfg.COMMAND_ALIAS.get(message_raw, message_raw)
4954

5055
tokens = message.split(" ")
5156

5257
if len(tokens) != 3:
53-
m = "Invalid: {}".format(message_raw)
58+
m = f"Invalid: {message_raw}"
5459
logger.warning(m)
5560
return m
5661

@@ -66,29 +71,29 @@ async def handle_command(self, message_raw):
6671
# Process a Zone Command
6772
if element_type == "zone":
6873
if not await self.alarm.control_zone(element, command):
69-
m = "Zone command error: {}={}".format(element, command)
74+
m = f"Zone command error: {element}={command}"
7075
logger.warning(m)
7176
return m
7277

7378
# Process a Partition Command
7479
elif element_type == "partition":
7580
if not await self.alarm.control_partition(element, command):
76-
m = "Partition command error: {}={}".format(element, command)
81+
m = f"Partition command error: {element}={command}"
7782
logger.warning(m)
7883
return m
7984

8085
# Process an Output Command
8186
elif element_type == "output":
8287
if not await self.alarm.control_output(element, command):
83-
m = "Output command error: {}={}".format(element, command)
88+
m = f"Output command error: {element}={command}"
8489
logger.warning(m)
8590
return m
8691
else:
87-
m = "Invalid control element: {}".format(element)
92+
m = f"Invalid control element: {element}"
8893
logger.error(m)
8994
return m
9095

91-
logger.info("OK: {}".format(message_raw))
96+
logger.info(f"OK: {message_raw}")
9297
return "OK"
9398

9499
# TODO: Remove this (to panels?)

0 commit comments

Comments
 (0)