From f6b5f602585baae9cf89d18f0e3f768c4b63defc Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Wed, 13 Feb 2019 13:49:36 -0500 Subject: [PATCH] backends: better error handling on remote funcs Signed-off-by: Alfredo Deza --- remoto/backends/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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']) -- 2.39.5