summaryrefslogtreecommitdiff
path: root/alot/ui.py
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2017-01-20 15:33:21 -0800
committerGitHub <noreply@github.com>2017-01-20 15:33:21 -0800
commitc1c6953e89755e849fa6191a288ebb8ba0057792 (patch)
tree223029943a3545f26fb690c900e7d3d34b24ffb0 /alot/ui.py
parent1db02607689750b82fa0ccb7640e1d6192a69afd (diff)
parent62674daafc5685597460d454129f207bd693a8d5 (diff)
Merge pull request #966 from dcbaker/pr/fix-965
alot/ui: Handle Exceptions in UI.apply_command callbacks
Diffstat (limited to 'alot/ui.py')
-rw-r--r--alot/ui.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/alot/ui.py b/alot/ui.py
index 8b3ac790..a521e9a0 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -112,6 +112,19 @@ class UI(object):
# start urwids mainloop
self.mainloop.run()
+ def _error_handler(self, failure):
+ """Default handler for exceptions in callbacks."""
+ if failure.check(CommandParseError):
+ self.notify(failure.getErrorMessage(), priority='error')
+ elif failure.check(CommandCanceled):
+ self.notify("operation cancelled", priority='error')
+ else:
+ logging.error(failure.getTraceback())
+ errmsg = failure.getErrorMessage()
+ if errmsg:
+ msg = "{}\n(check the log for details)".format(errmsg)
+ self.notify(msg, priority='error')
+
def _input_filter(self, keys, raw):
"""
handles keypresses.
@@ -229,19 +242,8 @@ class UI(object):
for cmdstring in split_commandline(cmdline):
d.addCallback(apply_this_command, cmdstring)
- # add sequence-wide error handler
- def errorHandler(failure):
- if failure.check(CommandParseError):
- self.notify(failure.getErrorMessage(), priority='error')
- elif failure.check(CommandCanceled):
- self.notify("operation cancelled", priority='error')
- else:
- logging.error(failure.getTraceback())
- errmsg = failure.getErrorMessage()
- if errmsg:
- msg = "%s\n(check the log for details)"
- self.notify(msg % errmsg, priority='error')
- d.addErrback(errorHandler)
+ d.addErrback(self._error_handler)
+
return d
@staticmethod
@@ -668,7 +670,7 @@ class UI(object):
prehook = cmd.prehook or (lambda **kwargs: None)
d = defer.maybeDeferred(prehook, ui=self, dbm=self.dbman, cmd=cmd)
d.addCallback(call_apply)
- d.addCallback(call_posthook)
+ d.addCallbacks(call_posthook, self._error_handler)
return d
def handle_signal(self, signum, frame):