]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: try harder when pickle fails to marshal an exception
authorKefu Chai <kchai@redhat.com>
Tue, 3 Mar 2020 16:18:35 +0000 (00:18 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 3 Mar 2020 17:52:02 +0000 (01:52 +0800)
pickle cannot marshal instances of class not defined in the top level of
a module. for instance, `DriveGroupValidationError` is defined in a
submodule of `ceph` python module, that's why we cannot capture it.

this prevent the `ceph` command line from getting a proper error when
the command fails if the command is implemented using cross python
module call(s).

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/orchestrator/_interface.py

index de285f64c60e00bc9fd7c38b4f36f966ea37fb88..d1e3478230fefb0ab089f47380ee8d21395c2df5 100644 (file)
@@ -247,9 +247,14 @@ class _Promise(object):
         self._exception_ = e
         try:
             self._serialized_exception_ = pickle.dumps(e) if e is not None else None
-        except Exception:
-            logger.exception("failed to pickle {}".format(e))
-            # We can't properly raise anything here. Just hope for the best.
+        except pickle.PicklingError:
+            logger.error(f"failed to pickle {e}")
+            if isinstance(e, Exception):
+                e = Exception(*e.args)
+            else:
+                e = Exception(str(e))
+            # degenerate to a plain Exception
+            self._serialized_exception_ = pickle.dumps(e)
 
     @property
     def _serialized_exception(self):