[core/input] Handle exceptions for non-existent commands
This commit is contained in:
parent
944b223f1e
commit
52e5ad7b43
2 changed files with 15 additions and 1 deletions
|
@ -44,6 +44,10 @@ def __invoke(event, callback):
|
||||||
if callable(cb):
|
if callable(cb):
|
||||||
cb(event)
|
cb(event)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
util.cli.execute(cb, wait=False)
|
util.cli.execute(cb, wait=False)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error('failed to invoke callback: {}'.format(e))
|
||||||
|
return
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -55,4 +55,14 @@ class config(unittest.TestCase):
|
||||||
core.input.trigger(self.someEvent)
|
core.input.trigger(self.someEvent)
|
||||||
cli.execute.assert_called_once_with(self.someCommand, wait=False)
|
cli.execute.assert_called_once_with(self.someCommand, wait=False)
|
||||||
|
|
||||||
|
def test_non_existent_callback(self):
|
||||||
|
with unittest.mock.patch('core.input.util.cli') as cli:
|
||||||
|
cli.execute.return_value = ''
|
||||||
|
cli.execute.side_effect = RuntimeError('some-error')
|
||||||
|
core.input.register(self.inputObject, self.someEvent['button'], self.someCommand)
|
||||||
|
try:
|
||||||
|
core.input.trigger(self.someEvent)
|
||||||
|
except Exception:
|
||||||
|
self.fail('input module propagated exception')
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue