]> git.apps.os.sepia.ceph.com Git - remoto.git/commitdiff
backends: better error handling on remote funcs
authorAlfredo Deza <alfredo@deza.pe>
Wed, 13 Feb 2019 18:49:36 +0000 (13:49 -0500)
committerAlfredo Deza <alfredo@deza.pe>
Wed, 13 Feb 2019 20:14:36 +0000 (15:14 -0500)
Signed-off-by: Alfredo Deza <alfredo@deza.pe>
remoto/backends/__init__.py

index 49871fb86c3d71907f2936bace646f7d2a92272f..1ac42256c16a72139cacd8107c4c1e4b83898346 100644 (file)
@@ -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 "<stdin>", in <module>',
+                        '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'])