From 52e5ad7b432688080206316a118346330c4e2bfd Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sat, 4 Apr 2020 08:17:35 +0200 Subject: [PATCH] [core/input] Handle exceptions for non-existent commands --- core/input.py | 6 +++++- tests/core/test_input.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/input.py b/core/input.py index 1a0037f..4f21b12 100644 --- a/core/input.py +++ b/core/input.py @@ -44,6 +44,10 @@ def __invoke(event, callback): if callable(cb): cb(event) else: - util.cli.execute(cb, wait=False) + try: + 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 diff --git a/tests/core/test_input.py b/tests/core/test_input.py index 8e68f4c..9d7885e 100644 --- a/tests/core/test_input.py +++ b/tests/core/test_input.py @@ -55,4 +55,14 @@ class config(unittest.TestCase): core.input.trigger(self.someEvent) 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