Catch exceptions in button handlers
This commit is contained in:
parent
7d90574212
commit
693d2ebdb7
@ -94,25 +94,28 @@ class Module(SettingsBase):
|
|||||||
else:
|
else:
|
||||||
args = []
|
args = []
|
||||||
|
|
||||||
our_method = is_method_of(cb, self)
|
try:
|
||||||
if callable(cb) and not our_method:
|
our_method = is_method_of(cb, self)
|
||||||
self.__log_button_event(button, cb, args, "Python callback")
|
if callable(cb) and not our_method:
|
||||||
cb(*args)
|
self.__log_button_event(button, cb, args, "Python callback")
|
||||||
elif our_method:
|
cb(*args)
|
||||||
cb(self, *args)
|
elif our_method:
|
||||||
elif hasattr(self, cb):
|
cb(self, *args)
|
||||||
if cb is not "run":
|
elif hasattr(self, cb):
|
||||||
# CommandEndpoint already calls run() after every
|
if cb is not "run":
|
||||||
# callback to instantly update any changed state due
|
# CommandEndpoint already calls run() after every
|
||||||
# to the callback's actions.
|
# callback to instantly update any changed state due
|
||||||
self.__log_button_event(button, cb, args, "Member callback")
|
# to the callback's actions.
|
||||||
getattr(self, cb)(*args)
|
self.__log_button_event(button, cb, args, "Member callback")
|
||||||
else:
|
getattr(self, cb)(*args)
|
||||||
self.__log_button_event(button, cb, args, "External command")
|
else:
|
||||||
if hasattr(self, "data"):
|
self.__log_button_event(button, cb, args, "External command")
|
||||||
args = [arg.format(**self.data) for arg in args]
|
if hasattr(self, "data"):
|
||||||
cb = cb.format(**self.data)
|
args = [arg.format(**self.data) for arg in args]
|
||||||
execute(cb + " " + " ".join(args), detach=True)
|
cb = cb.format(**self.data)
|
||||||
|
execute(cb + " " + " ".join(args), detach=True)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.critical("Exception while processing button callback: {!r}".format(e))
|
||||||
|
|
||||||
# Notify status handler
|
# Notify status handler
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user