diff --git a/mistral/engine/rpc.py b/mistral/engine/rpc.py index 8e543d2e..4311ad42 100644 --- a/mistral/engine/rpc.py +++ b/mistral/engine/rpc.py @@ -227,6 +227,12 @@ class EngineServer(object): return self._engine.resume_workflow(execution_id) +def _wrap_exception_and_reraise(exception): + message = "%s: %s" % (exception.__class__.__name__, exception.message) + + raise exc.MistralException(message) + + def wrap_messaging_exception(method): """This decorator unwrap remote error in one of MistralException. @@ -242,9 +248,14 @@ def wrap_messaging_exception(method): try: return method(*args, **kwargs) - except client.RemoteError as e: - exc_cls = getattr(exc, e.exc_type) - raise exc_cls(e.value) + except exc.MistralException: + raise + except (client.RemoteError, Exception) as e: + if hasattr(e, 'exc_type') and hasattr(exc, e.exc_type): + exc_cls = getattr(exc, e.exc_type) + raise exc_cls(e.value) + + _wrap_exception_and_reraise(e) return decorator diff --git a/mistral/tests/unit/engine/test_default_engine.py b/mistral/tests/unit/engine/test_default_engine.py index 313556ff..4bce75dc 100644 --- a/mistral/tests/unit/engine/test_default_engine.py +++ b/mistral/tests/unit/engine/test_default_engine.py @@ -440,3 +440,18 @@ class DefaultEngineWithTransportTest(eng_test_base.EngineTestCase): {}, 'some_description' ) + + def test_engine_client_remote_error_arbitrary(self): + mocked = mock.Mock() + mocked.call.side_effect = KeyError('wrong key') + self.engine_client._client = mocked + + exception = self.assertRaises( + exc.MistralException, + self.engine_client.start_workflow, + 'some_wf', + {}, + 'some_description' + ) + + self.assertIn('KeyError: wrong key', exception.message)