From 86942b6bf92832079e247325de5fa82231674d23 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 8 Sep 2018 01:09:55 +0100 Subject: [PATCH] ansible: add explanatory exception If disconnection occurs during a Connection.call(), return AnsibleConnectionFailure. --- ansible_mitogen/connection.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index bf11bccb..c35717dc 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -725,6 +725,20 @@ class Connection(ansible.plugins.connection.ConnectionBase): else: return call_context.call_async(func, *args, **kwargs) + call_aborted_msg = ( + 'Mitogen was disconnected from the remote environment while a call ' + 'was in-progress. If you feel this is in error, please file a bug. ' + 'Original error was: %s' + ) + + def _call_rethrow(self, recv): + try: + return recv.get().unpickle() + except mitogen.core.ChannelError as e: + raise ansible.errors.AnsibleConnectionFailure( + self.call_aborted_msg % (e,) + ) + def call(self, func, *args, **kwargs): """ Start and wait for completion of a function call in the target. @@ -739,7 +753,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): recv = self.call_async(func, *args, **kwargs) if recv is None: # no_reply=True return None - return recv.get().unpickle() + return self._call_rethrow(recv) finally: LOG.debug('Call took %d ms: %r', 1000 * (time.time() - t0), mitogen.parent.CallSpec(func, args, kwargs))