From 4b6135449554a5408cf49d83a007b872000462ca Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Mon, 16 Dec 2019 11:01:42 +0100 Subject: [PATCH] mgr/orchestrator: Raise more expressive Error, if completion already finished Eases debugging of tracebacks. Signed-off-by: Sebastian Wagner --- src/pybind/mgr/orchestrator.py | 3 +++ src/pybind/mgr/tests/test_orchestrator.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 27d3b8f3d35..ab61c4e297e 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -318,6 +318,9 @@ class _Promise(object): Sets the whole completion to be faild with this exception and end the evaluation. """ + if self._state == self.FINISHED: + raise ValueError( + 'Invalid State: called fail, but Completion is already finished: {}'.format(str(e))) assert self._state in (self.INITIALIZED, self.RUNNING) logger.exception('_Promise failed') self._exception = e diff --git a/src/pybind/mgr/tests/test_orchestrator.py b/src/pybind/mgr/tests/test_orchestrator.py index 584c407cb4c..4dd9db76cd9 100644 --- a/src/pybind/mgr/tests/test_orchestrator.py +++ b/src/pybind/mgr/tests/test_orchestrator.py @@ -228,6 +228,11 @@ def test_fail(): c._first_promise.fail(KeyError()) assert isinstance(c.exception, KeyError) + with pytest.raises(ValueError, + match='Invalid State: called fail, but Completion is already finished: {}'.format( + str(ZeroDivisionError()))): + c._first_promise.fail(ZeroDivisionError()) + def test_pretty_print(): mgr = mock.MagicMock() -- 2.39.5