From: Alfredo Deza Date: Wed, 13 Feb 2019 18:49:36 +0000 (-0500) Subject: backends: better error handling on remote funcs X-Git-Tag: 1.0.0~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f6b5f602585baae9cf89d18f0e3f768c4b63defc;p=remoto.git backends: better error handling on remote funcs Signed-off-by: Alfredo Deza --- diff --git a/remoto/backends/__init__.py b/remoto/backends/__init__.py index 49871fb..1ac4225 100644 --- a/remoto/backends/__init__.py +++ b/remoto/backends/__init__.py @@ -190,7 +190,7 @@ class LegacyModuleExecute(object): dump_template = """ if __name__ == '__main__': - import json + import json, traceback obj = {'return': None, 'exception': None} try: obj['return'] = %s%s @@ -235,6 +235,19 @@ class JsonModuleExecute(object): source = self._module_source + dump_template % (name, '()') out, err, code = check(self.conn, ['python'], stdin=source.encode('utf-8')) + if not out: + if not err: + err = [ + 'Traceback (most recent call last):', + ' File "", in ', + 'Exception: error calling "%s"' % name + ] + if code: + raise Exception('Unexpected remote exception: \n%s' % '\n'.join(err)) + # at this point, there was no stdout, and the exit code was 0, + # we must return so that we don't fail trying to serialize back + # the JSON + return response = json.loads(out[0]) if response['exception']: raise Exception(response['exception'])